WCF MaxStringContentLength is never updated!

1.8k views Asked by At

Coders, This problem is driving me crazy!! I have been doing extensive research for the last 2 days and I have no idea what is going on.

The Problem: As the title says, I have a WCF service that gets consumed by a silverlight application. The problem is that whenever I try to consume one of the WCF operations I receive this error:

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

I know that I am supposed to change the value of MaxStringContentLength in the web.config to something that fits my message size, but it appears to me that updating the value of MaxStringContentLength does not get reflected in the system. I tried to update service reference, rebuilt the whole solution with no luck and still get the same error. Any idea of what am I supposed to do?

Solution Info:

  • Asp.net project with WCF folder.

  • Silverlight project that consumes the WCF.

Web.config

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding 
      name="BasicHttpBinding_Service1" 
      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="10000" 
        maxArrayLength="16384"
        maxBytesPerRead="4096" 
        maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint 
    address="http://localhost:53931/WCF/Service1.svc" 
    binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_Service1"
    contract="ServiceReference.Service1"
    name="BasicHttpBinding_Service1" />
</client>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

ServiceReferences.ClientConfig

<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding 
              name="BasicHttpBinding_Service1" 
              maxBufferSize="2147483647"
              maxReceivedMessageSize="2147483647"

              >
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint 
          address="http://localhost:53931/WCF/Service1.svc" 
          binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_Service1"

          contract="ServiceReference.Service1"
          name="BasicHttpBinding_Service1" />
    </client>
</system.serviceModel>

Thanks in advance.

1

There are 1 answers

2
Sander On

I do not see the service defined anywhere in the web.config file - you just have a service client definition in there. I am surprised the service even works like this. Copy and paste error maybe?

Here is my web.config for a similar scenario (you are missing the marked part):

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <behaviors>
        <serviceBehaviors>
            <behavior name="MyDefaultBehavior">
                <serviceMetadata httpGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <basicHttpBinding>
            <binding name="MyDefaultBinding" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000">
                <readerQuotas maxDepth="500" maxArrayLength="20000000" maxStringContentLength="20000000"/>
            </binding>
        </basicHttpBinding>
    </bindings>
    <services> <!-- This appears missing from your web.config -->
        <service behaviorConfiguration="MyDefaultBehavior" name="MyProject.MyService">
            <endpoint address="" binding="basicHttpBinding" contract="MyProject.IMyService" bindingConfiguration="MyDefaultBinding" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
</system.serviceModel>