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

    Question

  • 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!



    Friday, March 28, 2008 2:56 AM

Answers

  • 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 4:40 AM

All replies

  • 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?

    Sunday, March 30, 2008 12:13 AM
  • 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 4:40 AM
  • 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>

    Monday, March 31, 2008 7:21 PM
  • 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.

    Tuesday, April 01, 2008 1:31 PM
  • 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.


    Wednesday, July 02, 2008 5:56 PM
  •  

    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.

    Thursday, July 03, 2008 1:27 AM
  • 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!

     

    Tuesday, July 08, 2008 4:47 PM
  • 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 07, 2008 11:43 PM
  • 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...
    Friday, November 21, 2008 6:30 PM
  • Dan, thanks a ton.  Massive help!!
    Tuesday, February 24, 2009 5:07 AM
  • 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
    Tuesday, June 16, 2009 8:51 PM
  • Have you found a resolution. I am having the same problem.
    Thursday, August 27, 2009 6:30 PM
  • I used both in web.config and did not get time after that to explore this. Thanks for reminding.
    Saturday, September 05, 2009 7:10 AM
  • 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.
    Thursday, September 10, 2009 8:47 AM
  • Wow thanks it worked

    Thursday, May 20, 2010 9:29 AM
  • Thanks Dan! It works now.
    Sunday, May 30, 2010 8:43 PM
  • Thanks Dan!  You saved me tons of time.  The key is for maxStringContentLength is Server Side settings  and maxReceivedMessageSize is client side.

    MSFT need to report better on WCF configuration errors,  developers are spending tons of time figuring out  and debugging WCF configuration settings. The settings are complex and is not straightforward.  They got to make it simpler or develop better tool ( SVCConfigEditor does not help too much)

     

     

     

    Wednesday, September 01, 2010 5:34 PM
  • You can make use of the sample Application
    
    You can download from the Below Link
    
    <a href="http://www.4shared.com/file/YD3GYE8K/SampleApplication.html">Sample Application.zip</a>
    
    Monday, March 07, 2011 4:32 PM
  • 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>

     

      

    I spent half a day to solve this problem. Fortunate to find your post which solved my problem in 5 mins. Thanks
    Bhavesh
    • Proposed as answer by bhav27 Monday, September 26, 2011 2:20 PM
    Monday, September 26, 2011 2:19 PM
  • I'm still struggling with this.  I have a silverlight 4 client consuming and passing values to my web service.  No matter what I seem to be doing, I can't get a string longer than 8k to pass through.  My endpoint in the web.config does specify a binding configuration, which has the size updated.  On the client, the readerQuotas is not a valid child element for the service, so I don't have any way to specify size on the client.  But apparently I shouldn't need to - what am I missing here?  I've taken out references to the other services for the sake of clarity...

    Web.config:

        <system.serviceModel>
            <services>
                <service behaviorConfiguration="MapPDFServiceBehavior" name="WCFService.MapPDFService">
                    <endpoint address="" binding="basicHttpBinding" contract="WCFService.IMapPDFService" bindingConfiguration="BasicHttpBinding_IMapPDFService"/>
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
                </service>
            </services>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_IMapPDFService" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:05:00" sendTimeout="00:05:00" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
                        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                        <security mode="None"/>
                    </binding>
                </basicHttpBinding>
            </bindings>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="MapPDFServiceBehavior">
                        <serviceMetadata httpGetEnabled="true"/>
                        <serviceDebug includeExceptionDetailInFaults="false"/>
                    </behavior>
                    <behavior name="">
                        <serviceMetadata httpGetEnabled="true"/>
                        <serviceDebug includeExceptionDetailInFaults="false"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
    

    Client Services Config in Silverlight App:

    <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_IMapLayerService" maxBufferSize="2147483647"
                        maxReceivedMessageSize="2147483647">
                        <security mode="None" />
                    </binding>
                    <binding name="BasicHttpBinding_IMapPDFService" maxBufferSize="2147483647"
                        maxReceivedMessageSize="2147483647">
                        <security mode="None" />
                        
                    </binding>
                    <binding name="BasicHttpBinding_ISiteUtilityService" maxBufferSize="2147483647"
                        maxReceivedMessageSize="2147483647">
                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="../MapLayerService.svc" binding="basicHttpBinding"
                    bindingConfiguration="BasicHttpBinding_IMapLayerService" contract="MapLayerService1.IMapLayerService"
                    name="BasicHttpBinding_IMapLayerService" />
                <endpoint address="../MapPDFService.svc" binding="basicHttpBinding"
                    bindingConfiguration="BasicHttpBinding_IMapPDFService" contract="MapPDFService1.IMapPDFService"
                    name="BasicHttpBinding_IMapPDFService" />
                <endpoint address="../SiteUtilityService.svc" binding="basicHttpBinding"
                    bindingConfiguration="BasicHttpBinding_ISiteUtilityService"
                    contract="SiteUtilityService1.ISiteUtilityService" name="BasicHttpBinding_ISiteUtilityService" />
            </client>
    


    Thursday, October 27, 2011 4:11 PM
  • MHylden - Did you ever find a solution to this?   I'm having the exact same problem.  
    Tuesday, June 26, 2012 3:06 PM
  • Nevermind - I found my problem.  On the server side I had binding set to "customBinding" in the endpoint, but I had made all the size changes in "basicHttpBinding"...  
    Tuesday, June 26, 2012 3:13 PM