问题描述:

I have a WCF service that is hosted locally. My web.config looks like this:

<system.serviceModel>

<bindings>

<basicHttpBinding>

<binding name="BasicHttpBinding_INavigationService" closeTimeout="00:01:00"

openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

maxBufferSize="6553600" maxBufferPoolSize="5242880" maxReceivedMessageSize="6553600"

messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

useDefaultWebProxy="true">

<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"

maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

<security mode="None">

<transport clientCredentialType="None" proxyCredentialType="None"

realm="" />

<message clientCredentialType="UserName" algorithmSuite="Default" />

</security>

</binding>

</basicHttpBinding>

</bindings>

<client>

<endpoint address="http://localhost/WebServices/NavigationService.svc/"

binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_INavigationService"

contract="NavigationService.INavigationService" name="BasicHttpBinding_INavigationService" />

</client>

</system.serviceModel>

My service works fine if I pass in less then 8K of text. Anything more and I get the following error:

Sys.WebForms.PageRequestManagerServerErrorException: The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'UpdateSiteMap'. 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 75, position 166

Can someone tell me how to increase the text quota? As you can see, I have it set to maximum integer size.

EDIT

After Tim's suggestion, here is my new Web.Config file:

<system.serviceModel>

<bindings>

<basicHttpBinding>

<binding closeTimeout="00:01:00"

openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

maxBufferSize="6553600" maxBufferPoolSize="5242880" maxReceivedMessageSize="6553600"

messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

useDefaultWebProxy="true">

<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"

maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

<security mode="None">

<transport clientCredentialType="None" proxyCredentialType="None"

realm="" />

<message clientCredentialType="UserName" algorithmSuite="Default" />

</security>

</binding>

</basicHttpBinding>

</bindings>

<client>

<endpoint address="http://localhost/WebServices/NavigationService.svc/"

binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_INavigationService"

contract="NavigationService.INavigationService" name="BasicHttpBinding_INavigationService" />

</client>

<services>

<service name="Navigation.INavigationService">

<endpoint address=""

binding="basicHttpBinding"

bindingConfiguration="BasicHttpBinding_INavigationService"

contract="NavigationService.INavigationService" />

</service>

</services>

网友答案:

Based on the error message and your description of the issue, you need to ensure that you have the same settings for your service, referencing the same defined binding in the bindingConfig attirbute of the endpoint element:

<system.serviceModel>
  <services>
    <service name="Navigation.INavigationService">
      <endpoint address="" 
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_INavigationService"
                contract="NavigationService.INavigationService" />
    </service>
  </services>
</system.serviceModel>

If you're using .NET 4.0 and have not specified the service element, then you are using a default endpoint and default binding (which means your limited to 8192 for maxStringContentLength). The easiest way to overcome this is to remove the name attribute from the binding section of your config - .NET will then use your definition as the default binding. For example:

<binding closeTimeout="00:01:00" ....

Note no name attribute is set.

You may need to use option 1 in this case, or create a similar binding definition with no name, as I'm not 100% sure that default bindings are used for the clients; they definitely are for the service.

See A Developer's Introduction to Windows Communication Foundation 4 for more information on default bindings and endpoints.

Additional Answer Based On Edit

Try this:

<client>
  <endpoint address="http://localhost/WebServices/NavigationService.svc/"
            binding="basicHttpBinding" 
            contract="NavigationService.INavigationService" 
            name="BasicHttpBinding_INavigationService" />
</client>

Delete the <services> section as the default endpoint mechanism for WCF 4.0 will handle that for you, and delete the bindingConfiguration attribute from the client endpoint.

相关阅读:
Top