4

We're trying to send a large xml string to a service method in WCF and we're getting the error

The maximum string content length quota (8192) has been exceeded while reading XML data.

The error suggests increasing the maxstringcontentlength although we weren't sure if we were supposed to do this on the client side or the server side or both. We've tried putting in on both but we still seem to get the error. I'm going to post the client and service configs below. I'm assuming there is a problem with one or both of them preventing this from working.

Any suggestions?

Client:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_ITESTService" 
                closeTimeout="00:01:00" openTimeout="00:01:00" 
                receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" 
                hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288"  
                maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" 
                transferMode="Buffered" useDefaultWebProxy="true">
               <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="4096" 
                    maxNameTableCharCount="2147483647" />
               <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint name="BasicHttpBinding_ITESTService"  
            address="http://localhost/TESTService.svc" 
            binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_ITESTService" 
            contract="TESTService.ITESTService" />
    </client>
</system.serviceModel>

Server:

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
          <binding
              name="BasicHttpBinding_Service1"
              maxBufferSize="2147483647"
              maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" 
              maxStringContentLength="2147483647" maxArrayLength="2147483647"
              maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
       <service name="TESTService">
          <endpoint name="BasicHttpBinding_Service1"
              address="http://localhost/TESTService.svc"
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_Service1"
              contract="ITESTService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
gleasonomicon
  • 1,069
  • 5
  • 13
  • 24

4 Answers4

2

Try adding a 'default' binding (without any name specified). Add the readerQuota settings to this binding.

You can then even remove the readerQuota settings from the named binding you are actually using.

This worked for me (although I'm not sure why the readerQuotas on the correct named binding are ignored by WCF)

chown
  • 51,908
  • 16
  • 134
  • 170
D.Tiemstra
  • 21
  • 2
1

'default' binding option worked for me. I was trying customize maxStringContentLength value in named WebHttpBinding but for some reason it did not picked up by WCF. finally I followed the D.Tiemstra work around then it started working.

    <webHttpBinding>         
    <binding  maxReceivedMessageSize="2147483647" > 
      <readerQuotas maxDepth="2147483647"
       maxStringContentLength="2147483647"
       maxArrayLength="2147483647"
       maxBytesPerRead="2147483647"
       maxNameTableCharCount="2147483647" />
    </binding>
  </webHttpBinding>
  • I don't these max values are correct, I would go with: `MaxBufferSize = 2147483647, MaxBufferPoolSize = 524288, MaxReceivedMessageSize = 2147483647, ReaderQuotas = new XmlDictionaryReaderQuotas { MaxDepth = 32, MaxStringContentLength = 8192, MaxArrayLength = 16384, MaxBytesPerRead = 4096, MaxNameTableCharCount =1638 }` – DanielV Sep 28 '17 at 09:08
0

I would use this values for the WCF configuration (programmatically):

Security = { Mode = SecurityMode.None},
CloseTimeout = TimeSpan.MaxValue,
OpenTimeout = TimeSpan.MaxValue,
SendTimeout = TimeSpan.FromMinutes(5),
ReceiveTimeout = TimeSpan.FromMinutes(5),
MaxBufferSize = 2147483647,
MaxBufferPoolSize = 524288,
MaxReceivedMessageSize = 2147483647,
ReaderQuotas = new XmlDictionaryReaderQuotas
{
   MaxDepth = 32,
   MaxStringContentLength = 8192,
   MaxArrayLength = 16384,
   MaxBytesPerRead = 4096,
   MaxNameTableCharCount =1638
}
DanielV
  • 2,076
  • 2
  • 40
  • 61
0

This thread explains in detail how to specify the binding settings on server and client correctly in order to change the MaxStringContentLength.

This other thread also provides a clear and efficient answer on using the readerQuotas.

Community
  • 1
  • 1
Peladao
  • 4,036
  • 1
  • 23
  • 43