While working on a WCF service, I received this error message when trying to return long string data from a method:
An exception of type 'System.ServiceModel.Dispatcher.NetDispatcherFaultException' occurred in mscorlib.dll but was not handled in user code
Additional information: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:ClientPrintResult. The InnerException message was 'There was an error deserializing the object of type System.String. 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 2, position 40523.'. Please see InnerException for more details.
Being somewhat new to WCF, I assumed there was some configuration I could set somewhere to address this issue. And after a bit of searching, I found the right configuration element: readerQuotas. Here's a segment of a client side configuration file with this element in context:
In this configuration sample, all of the readerQuotas attributes are set to ridiculously large values, which may not be the best choice from a security perspective. The documentation for this element says that these constraints exist to help prevent denial of service attacks. One interesting thing to note is that this element is required only on client side configuration, not on the server.
Another related attribute is the maxReceivedMessageSize attribute on the binding element, which sets the maximum message size that can be processed. Like the readerQuotas element, it is only necessary to set this in client configuration.