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

  1. maxStringContentLength
  2. maxBufferSize
  3. 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>

Client Side web.config Summary

  1. maxStringContentLength
  2. maxBufferSize
  3. maxBufferPoolSize
  4. maxReceivedMessageSize
  5. maxStringContentLength

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.