Philippsen's Blog

Everyday findings in my world of .net and related stuff

WCF ReaderQuotas problem

Posted by Torben M. Philippsen on November 25, 2010

Working with WCF I often see errors similar to this:

“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.

This is a quite common issue and is caused by the fact that the message that is being received is too large according to the default configuration of the service binding. As the error description states the solution is to increase some of the values in the ReaderQuotas section of the client web.config file. (Please note that You are able to configure the same on the server side)

A sample web.config file where the ReaderQuotas properties have been set to their maximum values, is shown here:

<bindings>
<wsHttpBinding>
<binding name=”MyService” maxReceivedMessageSize=”2147483647“>
<readerQuotas maxDepth=”2147483647” maxStringContentLength=”2147483647
maxArrayLength=”2147483647” maxBytesPerRead=”2147483647
maxNameTableCharCount=”2147483647” />
<security mode=”TransportWithMessageCredential”>
<transport clientCredentialType=”None” />
<message clientCredentialType=”UserName” />
</security>
</binding>
</wsHttpBinding>
</bindings>

You might want to read the documentation for the ReaderQutotas before increasing the values

Advertisements

Sorry, the comment form is closed at this time.

 
%d bloggers like this: