【问题标题】:"The maximum string content length quota (8192) has been exceeded while reading XML data" error while sending XML string to WCF将 XML 字符串发送到 WCF 时出现“读取 XML 数据时超出最大字符串内容长度配额 (8192)”错误
【发布时间】:2013-03-27 08:54:53
【问题描述】:

我正在使用一个 .NET、C# 应用程序,该应用程序打算将一个长 XML 字符串发送到 WCF 服务方法以进行进一步操作。当我的应用程序尝试在运行时将 XML 字符串发送到 WCF 服务时,我收到一条错误消息:

"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:strProdUserDataXML. The InnerException message was 'There was an error deserializing the object of type System.String. 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 131, position 57.'. Please see InnerException for more details."

我的应用程序端 web.config 我已将“绑定”和“端点”编写为:

<binding name="EndPointHTTPGenericPortal" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    <security mode="None">
    <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
    </binding>

    <endpoint address="http://192.168.140.40/WcfGenericPortal_Service/Service1.svc" binding="basicHttpBinding" bindingConfiguration="EndPointHTTPGenericPortal" contract="IService1" name="EndPointHTTPGenericPortal" behaviorConfiguration="Graph" />

如果有任何机构可以帮助我解决这个错误,我将非常感激。 在此先感谢大家。

【问题讨论】:

  • 你的服务器端网络配置是什么?
  • 服务器端最大字符串内容长度配额的值是多少?
  • 嗨,Voo & Jocke,感谢您的回复。服务器端配置是:''
  • 你的“readerQuotas”节点在哪里?

标签: c# .net wcf web-config quota


【解决方案1】:

这是 MSDN 上关于 Reader Quotas 的文章。

似乎超出了您服务器端的读取器配额之一。

具体来说,超过了 ma​​xStringContentLengthma​​xStringContentLength 的默认值为 8192 个字符,如错误消息所述,已超出该值。

但正如其他人所建议的那样,将所有值提高到最大值 2147483647 可能不是最好的方法。

正如我链接的 MSDN 文档中所写:

复杂性限制可防止拒绝服务 (DOS) 攻击试图使用消息复杂性来捆绑 端点处理资源。其他复杂性约束包括 最大元素深度和字符串最大长度等项目 消息中的内容。

再加上您当前将安全模式设置为 - 您可能会遇到一些问题。

【讨论】:

  • 感谢 Derek W 的帮助。它帮助我解决了这个问题。我将最大值设置为 2147483647,它起作用了。
【解决方案2】:

我遇到了这个错误,并通过在客户端和服务器配置中为服务添加这个 MaxItemsInObjectGraph 属性来解决。

<dataContractSerializer maxItemsInObjectGraph="2147483647" />

服务器端

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="Service.Service1Behavior">
        <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      </behavior>
</system.serviceModel>

客户端

<behaviors >
  <endpointBehaviors>
    <behavior name="endpointbehaviour">
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
    </behavior>
  </endpointBehaviors>
</behaviors>

并且不要忘记将此行为应用于 EndPoint behaviorConfiguration="endpointbehaviour"

【讨论】:

  • 我花了无数小时来解决问题。您的解决方案帮我解决了,谢谢
【解决方案3】:

客户端绑定

    <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService11" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"
messageEncoding="Text">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647"
maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>

<behaviors>
<endpointBehaviors>
<behavior name="KAMServiceDistributor">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:1234/xxxx/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService11"
contract="yourservice namespae" name="AnyName" />
</client>
</system.serviceModel>

服务配置文件:

<system.serviceModel>
<behaviors>


<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding <b>maxReceivedMessageSize="2147483647"</b>>
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehaviour" name="Service">
<endpoint binding="basicHttpBinding" contract="IService" />
</service>
</services>
</system.serviceModel>

【讨论】:

  • 过滤所有答案后,您的答案对我有用..感谢您。
  • 是的,这个答案是最有用的,因为它显示了放置读者配额设置的位置!
【解决方案4】:

尝试在绑定中设置以下内容。

<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
    maxArrayLength="2147483647" maxBytesPerRead="2147483647"
    maxNameTableCharCount="2147483647" />

它解决了我的问题。如需更多参考,请查找以下链接http://blogfornet.com/2013/08/the-maximum-string-content-length-quota-8192-has-been-exceeded-while-reading-xml-data/

【讨论】:

  • 该链接现在转到一个保留页面。
【解决方案5】:

皮纳基·卡鲁里,

配额长度不仅取决于客户端的配置 - 它们还取决于服务器的配置。请发布您的 WCF 服务器的 web.config,以便我们对问题有所了解。您很可能已经为 8192 设置了配额,因此您最快的方法是找到并增加其价值。

更新

据我所知,您在服务器的 web.config 中缺少“readerQuotas”节点,因此 MaxStringContentLength 将其值设置为默认值 (8192)。更多信息请参考此链接:http://msdn.microsoft.com/en-us/library/system.xml.xmldictionaryreaderquotas.maxstringcontentlength.aspx

【讨论】:

  • 嗨 Piotr Justyana,感谢您的回复,服务器配置为:''
  • 请阅读我的更新答案和我在您的问题下的最后评论。
  • 感谢 Piotr Justyana,它成功了!!!!!!你很容易解决它。非常感谢你的链接帮助我很容易地解决它,而这对我来说是一场噩梦。
【解决方案6】:

检查客户端的目标框架是否与服务的目标框架相同。我遇到了这个问题并尝试了上述所有修复,但没有奏效。检查属性并检查目标框架并更改它。

【讨论】:

    【解决方案7】:

    服务器端

    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding maxBufferPoolSize="2147483647"
                         maxReceivedMessageSize="2147483647"
                         maxBufferSize="2147483647">
                    <readerQuotas maxDepth="200"
                                  maxStringContentLength="2147483647"
                                  maxArrayLength="16384"
                                  maxBytesPerRead="2147483647"
                                  maxNameTableCharCount="16384" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    </system.serviceModel>
    

    客户端

    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IRequestService" allowCookies="true"
            maxReceivedMessageSize="2147483647"
            maxBufferSize="2147483647"
            maxBufferPoolSize="2147483647">
                    <readerQuotas maxDepth="32"
              maxArrayLength="2147483647"
              maxStringContentLength="2147483647"/>
                </binding>
                <binding name="BasicHttpBinding_IAttachmentService" allowCookies="true"
            maxReceivedMessageSize="2147483647"
            maxBufferSize="2147483647"
            maxBufferPoolSize="2147483647">
                    <readerQuotas maxDepth="32"
              maxArrayLength="2147483647"
              maxStringContentLength="2147483647"/>
                </binding>
            </basicHttpBinding>
        </bindings>
    </system.serviceModel>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多