首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在创建XML读取器时增加MaxStringContentLength大小

如何在创建XML读取器时增加MaxStringContentLength大小
EN

Stack Overflow用户
提问于 2013-09-17 12:02:06
回答 1查看 3.1K关注 0票数 0

我收到以下错误:

格式化程序在试图反序列化消息时抛出一个异常:反序列化操作“InsertQuery”的请求消息正文中的错误。读取XML数据时已超出最大字符串内容长度配额(8192)。可以通过更改在创建XML读取器时使用的MaxStringContentLength对象上的XmlDictionaryReaderQuotas属性来增加此配额。第1行,位置33788。

为了增加MaxStringContentLength的大小,我修改了Web.config,如下所示。

代码语言:javascript
复制
<?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>

即使这样,我也会犯同样的错误:

请告诉我,为了解决这个问题,我需要做些什么改变。提前谢谢!!

EN

回答 1

Stack Overflow用户

发布于 2013-09-17 21:38:49

您是Web.config文件,表示您使用的是.NET 4.0,并且Web.config中没有显式定义的端点,因此WCF将为您提供一个默认端点(基于*.svc文件的位置),并为http方案使用basicHttpBinding的默认绑定。maxStringContentLength的默认值是8192。

要改变这种情况,您要么需要:

  1. 显式添加端点,并将您定义的绑定(使用绑定配置的name属性)分配给端点的bindingConfiguration属性,或
  2. 通过删除name属性,使您在配置文件中定义的绑定配置成为该类型绑定的默认配置,并将http的默认映射从basicHttpBinding更改为webHttpBinding

若要通过显式端点执行此操作,请将以下内容添加到Web.config文件中的<system.serviceModel>

代码语言:javascript
复制
<services>
  <service name="your service name">
    <endpoint address="" binding="webHttpBinding" 
              bindingConfiguration="webHttpBindingDev" 
              contract="your fully-qualified contract name" />
  </service>
</services>

您必须为您的服务名称和合同提供适当的值。

要通过设置默认值来完成此操作,需要删除webHttpBinding属性,将指定的webHttpBinding绑定配置标记为默认值:

代码语言:javascript
复制
<bindings>
  <webHttpBinding>
    <binding>
      <readerQuotas maxDepth="2147483647" 
                    maxStringContentLength="2147483647"  
                    maxArrayLength="2147483647" 
                    maxBytesPerRead="2147483647" 
                    maxNameTableCharCount="2147483647" />
    </binding>
  </webHttpBinding>
</bindings>

接下来,需要将webHttpBinding设置为http方案的默认绑定:

代码语言:javascript
复制
<protocolMapping>
  <add binding="webHttpBinding" scheme="http" />
</protocolMapping>

使用这两个更改,您将不需要添加显式端点。

此外,由于您使用的是webHttpBinding,所以我认为需要将以下内容添加到端点行为中:

代码语言:javascript
复制
<behaviors>
  <endpointBehaviors>
    <behavior>
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>

有关WCF 4中默认端点、绑定等的更多信息,请查看开发人员介绍Windows通信基金会4

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18849341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档