简体   繁体   English

创建XML阅读器时如何增加MaxStringContentLength大小

[英]How to increase the MaxStringContentLength size when creating the XML reader

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'. 格式化程序尝试反序列化消息时引发异常:反序列化“ InsertQuery”操作的请求消息主体时出错。 The maximum string content length quota (8192) has been exceeded while reading XML data. 读取XML数据时,已超出最大字符串内容长度配额(8192)。 This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. 通过更改在创建XML阅读器时使用的XmlDictionaryReaderQuotas对象上的MaxStringContentLength属性,可以增加此配额。 Line 1, position 33788. 第1行,位置33788。

To increase the size of MaxStringContentLength, i modified my Web.config as given below.. 为了增加MaxStringContentLength的大小,我如下所示修改了Web.config。

<?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 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. 您是Web.config文件,表示您正在使用.NET 4.0,并且Web.config中没有明确定义终结点,因此WCF为您提供了一个默认终结点(基于* .svc文件的位置) ,并为http方案使用basicHttpBinding的默认绑定。 The default for maxStringContentLength is 8192. maxStringContentLength的默认值为8192。

To change that, you either need to: 要更改此设置,您要么需要:

  1. 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 显式添加一个端点,并将您定义的绑定(使用绑定配置的“名称”属性)分配给端点的“ bindingConfiguration”属性,或者
  2. 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`. 通过删除“ name”属性,将配置文件中定义的绑定配置设为该绑定类型的默认配置,并将“ http”的默认映射从“ basicHttpBinding”更改为“ webHttpBinding”。

To do it via an explicit endpoint, add the following to your Web.config file under <system.serviceModel> : 要通过显式端点执行此操作,请将以下内容添加到<system.serviceModel>下的Web.config文件中:

<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: 要通过设置默认值来做到这一点,您需要通过删除name属性,将指定的webHttpBinding绑定配置标记为默认值:

<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: 接下来,您需要将webHttpBinding设置为http方案的默认绑定:

<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: 另外,由于您使用的是webHttpBinding ,因此我相信您需要在端点行为中添加以下内容:

<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. 有关WCF 4中默认终结点,绑定等的更多信息,请参阅Windows Communication Foundation 4的A Developer's Introduction

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM