WCF – The maximum string content length quota (8192) has been exceeded while reading XML data
Introduction
The DataContractSerializer in WCF serializes objects to XML Streams. There is a size (length) limitation on these streams. They are restricted by default to 8k (8192 bytes).
While this helps in avoiding Denial of Service (DoS) attacks, it is an incovenience for several service operations that DO return LARGER than 8k size objects. The resultset from a single query returned by a WCF service could constitute one such large object. When this happens, the WCF runtime throws an exception:
The maximum string content length quota (8192) has been exceeded while reading XML data.
To work around this limitation, certain web.config values need to be tweaked – both, on the client web.config as well as the server. Just having a client SEND a large message – without the server web.config configured to ACCEPT the message, will just throw a different exception. One needs to tweak both in conjunction as described below:
<bindings>
<basicHttpBinding>
<binding name="basicHttpConfiguration" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
Server Side web.config Summary
- maxStringContentLength
- maxBufferSize
- maxReceivedMessageSize
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="RequestProcessorBinding" receiveTimeout="00:30:00" sendTimeout="00:01:00"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.mydomain.com/wcfservice/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
contract="MyWcfServiceReference.IMyService" name="BasicHttpBinding_IMyService" />
</client>
</system.serviceModel>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="RequestProcessorBinding" receiveTimeout="00:30:00" sendTimeout="00:01:00"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.mydomain.com/wcfservice/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
contract="MyWcfServiceReference.IMyService" name="BasicHttpBinding_IMyService" />
</client>
</system.serviceModel>
Client Side web.config Summary
- maxStringContentLength
- maxBufferSize
- maxBufferPoolSize
- maxReceivedMessageSize
- maxStringContentLength
Thanks its worked,
thanks a lot