.NET Framework Developer Center > .NET Development Forums > Windows Communication Foundation > The maximum string content length quota (8192) has been exceeded while reading XML data.
Ask a questionAsk a question
 

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

  • Friday, March 28, 2008 2:56 AMFarrEver Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi, I have been working on implementing a WCF service and have run into this problem with the maxStringContentLength.  I have read a bunch of posts here on how to correct it and none of them have worked.  I have updated my web.config in my local IIS5 published service to be maxStringContentLength="2147483647" and have updated my application's app.config to be maxStringContentLength="2147483647".  I delete all DLL's, rebuild, restart IIS, make sure all VS 2008 virtual webs are stopped, republish multiple times...even reboot my machine and I continually receive the following error message:

    The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/Tongue TiedqlStatement. 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 171, position 35.'.  Please see InnerException for more details.

    I am running the service on my local machine: Win XP SP2, IIS5, .Net 3.5, VS 2008

    Here is my WCF service's servicemodel section of the web.config:
     
      <system.serviceModel>
        <bindings>
          <wsHttpBinding>
            <binding name="wsHttpBindingSettings" maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
          </wsHttpBinding>
        </bindings>
        <services>
          <service behaviorConfiguration="DataServiceBehavior" name="Zuko.Service.DataService">
            <endpoint address="" binding="wsHttpBinding" contract="Zuko.Service.IDataService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="DataServiceBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceThrottling maxConcurrentSessions="102222222" maxConcurrentInstances="2147483647" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>



    Here is my application's serviceModel section in the app.config:

        <system.serviceModel>
            <bindings>
                <wsHttpBinding>
                    <binding name="WSHttpBinding_IDataService" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                        allowCookies="false">
                        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                        <reliableSession ordered="true" inactivityTimeout="00:10:00"
                            enabled="false" />
                        <security mode="Message">
                            <transport clientCredentialType="Windows" proxyCredentialType="None"
                                realm="" />
                            <message clientCredentialType="Windows" negotiateServiceCredential="true"
                                algorithmSuite="Default" establishSecurityContext="true" />
                        </security>
                    </binding>
                </wsHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://obfuscated.com/Zuko_Services/DataService.svc"
                    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDataService"
                    contract="Zuko_Services.IDataService" name="WSHttpBinding_IDataService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
            </client>
        </system.serviceModel>



    NOTE: Everytime I "Update Service Reference" for the WCF service within my application, all of the readerQuotas reset back to their default values...including
    maxStringContentLength="8192".  I triple checked the web.config file where I have the service published on my local machine and it has maxStringContentLength="2147483647".

    Please help...this is driving me crazy.

    Thanks!



Answers

  • Monday, March 31, 2008 4:40 AMDan RigsbyMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    The settings for quotas dont really matter much on the client.  Its the server you need to worry about. You need to specify the binding settings to use.  You cant just specify information in the binding and expect the endpoint to use it.  You must include the binding configuration name in the endpoint like this:

     

        <services>
          <service behaviorConfiguration="DataServiceBehavior" name="Zuko.Service.DataService">
            <endpoint address="" binding="wsHttpBinding" contract="Zuko.Service.IDataService" bindingConfiguration="WSHttpBinding_IDataService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>

     

     

All Replies

  • Sunday, March 30, 2008 12:13 AMDavidAnderson Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I am having the same problem. Even with a higher setting, I still get the error that the MaxStringContentLength of 8192 has been exceeded. Have you found a solution?

  • Monday, March 31, 2008 4:40 AMDan RigsbyMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    The settings for quotas dont really matter much on the client.  Its the server you need to worry about. You need to specify the binding settings to use.  You cant just specify information in the binding and expect the endpoint to use it.  You must include the binding configuration name in the endpoint like this:

     

        <services>
          <service behaviorConfiguration="DataServiceBehavior" name="Zuko.Service.DataService">
            <endpoint address="" binding="wsHttpBinding" contract="Zuko.Service.IDataService" bindingConfiguration="WSHttpBinding_IDataService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>

     

     

  • Monday, March 31, 2008 7:21 PMDavidAnderson Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I added a bindingConfiguration as suggested above and now get an error message that the service could not be activated. Before adding the bindingConfiguration, I was not getting an error message (except that the maximum string content length of 8192 had been exceeded). Here is the services section of the server config file:

     

    <services>

    <service name="SessionStateWCF.Service1" behaviorConfiguration="SessionStateWCF.Service1Behavior">

    <endpoint address="" binding="wsHttpBinding"

    contract="IService1"

    bindingConfiguration="WSHttpBinding_IService1">

    <identity>

    <dns value="bsc1smstdb01"/>

    </identity>

    </endpoint>

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

    </service>

    </services>

  • Tuesday, April 01, 2008 1:31 PMDavidAnderson Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I think I may have resolved my own problem. It seems that the entire wsHttpBinding has to be copied from the client's web.config file and placed in the server's web.config file. Perhaps, that is obvious and I should have done it before but I haven't seen it documented anywhere. I am still testing but the WCF is now responding to changes in the maxStringContentLength.

  • Wednesday, July 02, 2008 5:56 PMkfj001 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    My problem was the oposite. My client's wsHttpBinding configuration was missing the size parameter, rather than the service...

    Shouldn't the metadata service thing tell clients how large the buffers should be to properly facilitate communication with the server?

     DavidAnderson wrote:

    I think I may have resolved my own problem. It seems that the entire wsHttpBinding has to be copied from the client's web.config file and placed in the server's web.config file. Perhaps, that is obvious and I should have done it before but I haven't seen it documented anywhere. I am still testing but the WCF is now responding to changes in the maxStringContentLength.


  • Thursday, July 03, 2008 1:27 AMChristian Findlay Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    FarrEver, just going back to your original post. You are missing the bindingConfiguration attribute on your endpoint. The endpoint won't use your binding because you haven't specified it. Should be something like this"

     

          <service behaviorConfiguration="DataServiceBehavior" name="Zuko.Service.DataService">
            <endpoint address="" binding="wsHttpBinding" contract="Zuko.Service.IDataService"

    bindingConfiguration="WSHttpBinding_IDataService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>

     

    Although, there is probably more to the configuration you'll need to do.

     

    Ooops! Someone beat me to the punch.

  • Tuesday, July 08, 2008 4:47 PMAshOnMsdn Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Dan, you just saved me huge load of trouble. I had already spent 3 hours on figuring out the problem and was preparing myself for the full day. Thanks thanks and thanks!

     

  • Friday, November 07, 2008 11:43 PMd1h Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I'm having the same problem with exceeding the maxStringContentLength.
    But my client is using Compact Framework 3.0.

    Since the app config is not supported and the classes do not seem to exist, any ideas on how I would resolve this issue?


    Thanks...
  • Friday, November 21, 2008 6:30 PMd1h Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Does anyone know how to resolve this issue?

    Does anyone know that it is NOT possible or IS possible to resolve without having to write code to manually manage splitting the data into several transmissions?

    Can someone point me in the right direction to find an answer?

    Any help would be greatly appreciated.

    Thanks...
  • Tuesday, February 24, 2009 5:07 AMleadmaverick Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Dan, thanks a ton.  Massive help!!
  • Tuesday, June 16, 2009 8:51 PMmkbansal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Dan, This was actually very helpful information.

    I also have a similar problem related to max size.

    I am having a WCF service hosted on IIS with below binding settings:

          <basicHttpBinding>
            <binding name="basicHttp" maxReceivedMessageSize="10485760" sendTimeout ="00:02:00" closeTimeout="00:02:00" openTimeout="00:02:00" maxBufferSize="10485760" maxBufferPoolSize ="41943040" >
              <readerQuotas maxDepth="100" maxArrayLength="10485760" maxBytesPerRead="10485760" maxStringContentLength="10485760" />
              <security mode="Transport">
                <transport clientCredentialType="Certificate" />
              </security>
            </binding>
          </basicHttpBinding>

    Because in my case I have to receive big messages up to 10 MB, I have set the higher maxReceivedMessageSize. But when I am sending a document of 8-9 MB to WCF service than it is giving an execption saying

    An error occurred while receiving the HTTP response to https://xxx/xxxx/xxxx.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details..

    Then I searched on the net and find I need to set
    <httpRuntime maxRequestLength="10240" executionTimeout="120"/>
    in web.config After setting httpRunTime, it started working.

    My question here is, Which one will be given preferences while calculating the max Request Size?
    httpRuntime maxRequestLength
    or
    binding maxReceivedMessageSize

    Thanks,
    MK
  • Thursday, August 27, 2009 6:30 PMjopv Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Have you found a resolution. I am having the same problem.
  • Saturday, September 05, 2009 7:10 AMmkbansal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I used both in web.config and did not get time after that to explore this. Thanks for reminding.
  • Thursday, September 10, 2009 8:47 AMPatrick Peters Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    It drove me crazy, but I rebuilded the service reference again (that creates the client proxy and app.config and xsd's) and it worked! The client had a older generated version of the service contract classes and config.