创建 XML 阅读器时如何增加 MaxStringContentLength 大小 [英] How to increase the MaxStringContentLength size when creating the XML reader
问题描述
我收到以下错误:
格式化程序在尝试反序列化消息时引发异常:反序列化操作InsertQuery"的请求消息正文时出错.读取 XML 数据时已超出最大字符串内容长度配额 (8192).可以通过更改创建 XML 阅读器时使用的 XmlDictionaryReaderQuotas 对象上的 MaxStringContentLength 属性来增加此配额.第 1 行,位置 33788.
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.
为了增加 MaxStringContentLength 的大小,我修改了我的 Web.config,如下所示..
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 !!
推荐答案
You're Web.config 文件表明您使用的是 .NET 4.0,并且 Web.config 中没有明确定义端点,因此 WCF 是为您提供一个默认端点(基于您的 *.svc 文件的位置),并为 http
方案使用 basicHttpBinding
的默认绑定.maxStringContentLength
的默认值为 8192.
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:
- 显式添加端点并将您定义的绑定(使用绑定配置的`name` 属性)分配给端点的`bindingConfiguration` 属性,或
- 通过移除 `name` 属性,使你在配置文件中定义的绑定配置成为该类型绑定的默认配置,并将 `http` 的默认映射从 `basicHttpBinding` 更改为 `webHttpBinding`.立>
要通过显式端点执行此操作,请将以下内容添加到
下的 Web.config 文件中:
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.
要通过设置默认值来实现,您需要通过删除 name
属性将 webHttpBinding
的指定绑定配置标记为默认值:
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>
接下来,您需要将 webHttpBinding
设置为 http
方案的默认绑定:
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.
此外,由于您使用的是 webHttpBinding
,我相信您需要将以下内容添加到端点行为中:
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>
查看开发人员对 Windows Communication Foundation 4 的介绍有关 WCF 4 中默认端点、绑定等的更多信息.
Take a look at A Developer's Introduction to Windows Communication Foundation 4 for more information on default endpoints, bindings, etc in WCF 4.
这篇关于创建 XML 阅读器时如何增加 MaxStringContentLength 大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!