问题
I am getting following error:
The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'InsertQuery'. 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 1, position 33788.
To increase the size of MaxStringContentLength, i modified my Web.config as given below..
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingDev">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Even then i am getting the same error :(
Please let me know what changes need to me made in order to resolve this issue. Thanks in advance !!
回答1:
You're Web.config file indicates that you're using .NET 4.0, and there is no endpoint explicitly defined in the Web.config, so WCF is giving you a default endpoint (based on the location of your *.svc file), and using the default binding of basicHttpBinding
for the http
scheme. The default for maxStringContentLength
is 8192.
To change that, you either need to:
- Add an endpoint explicitly and assign the binding you've defined (using the binding configuration's `name` attribute) to the endpoint's `bindingConfiguration` attribute, or
- make the binding configuration you've defined in your config file the default for that type of binding by removing the `name` attribute, and change the default mapping for `http` from `basicHttpBinding` to `webHttpBinding`.
To do it via an explicit endpoint, add the following to your Web.config file under <system.serviceModel>
:
<services>
<service name="your service name">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="webHttpBindingDev"
contract="your fully-qualified contract name" />
</service>
</services>
You'll have to supply the proper values for your service name and contract.
To do it via setting defaults, you'll need to mark your specified binding configuration for webHttpBinding
as the default by removing the name
attribute:
<bindings>
<webHttpBinding>
<binding>
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
</bindings>
Next you'll need to set webHttpBinding
as the default binding for the http
scheme:
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
With these two changes, you won't need to add an explicit endpoint.
Also, since you're using webHttpBinding
, I believe you need to add the following to the endpoint behaviors:
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
Take a look at A Developer's Introduction to Windows Communication Foundation 4 for more information on default endpoints, bindings, etc in WCF 4.
来源:https://stackoverflow.com/questions/18849341/how-to-increase-the-maxstringcontentlength-size-when-creating-the-xml-reader