22. June 2009 16:39
I have been running into some situations WCF barfs on calls where the message body is very large:
"The maximum string content length quota (8192) has been
exceeded while reading XML data. This quota may be increased by
changing the MaxStringContentLength property on the
XmlDictionaryReaderQuotas object used when creating the XML reader.
Line 3, position 9381."
Took a little poking around to see what exactly was going wrong here, but a couple of posts got me going in the right direction. In fact, this is a real excellent exception message in that it tells me exactly what I need to do to resolve the issue: increase the MaxStringContentLength property on the XmlDictionaryReadersQuotas object that the BasicHttpBinding class is using.
According to MSDN the MaxStringContentLength property:
"Gets or sets the maximum size for a message that can be received on a channel configured with this binding."
The purpose of this restriction being the possiblity of DoS attacks on a publicaly exposed service caused by arbitrarily large messages. Since I am using TransferMode.Buffered, the message size is bound by the size of the MaxReceivedMessageSize by default.
This is the end result:
15. June 2009 22:49
I needed to update a utilities class I have been using to support XDocument (not just XmlDocuments) when I hit upon creating an extension method instead of the typical static utility class/method approach. Extension methods are a simple and powerful means of adding behavior to existing classes without breaking encapsulation. I was initially skeptical of the idea, but they have turned out to be rather nice and syntically better than static utilities classes.
The XDocument class is key part of the LINQ to XML
API released with .NET Framework 3.5. Essentially it's a 'next'
generation replacement for the XmlDocument class with added
functionality for easily modifying in-memory Xml documents. Overall I prefer XDocument over XmlDocumentfor various reasons, but learning a new API can be a bit frustrating; it takes time to build a knowledge base of all of the 'gotchas' and 'hacks' ;)
Anyways, here is the final result:
Note that by convention I named the class after the class I was extending and added the 'Extensions' post fix. This makes things a little easier to manage. Here is the usage: