-->

错误在发送XML字符串WCF“而读取XML数据的最大串内容长度配额(8192)已被超过”(“The

2019-07-28 03:29发布

我使用的是.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" />

如果任何机构可以帮助我如何解决这个错误,我将非常感谢。 感谢所有提前。

Answer 1:

下面是关于MSDN的文章读者配额 。

看来,在你的服务器端的读者配额的一个被超过。

具体而言,maxStringContentLength被超过。 默认值是8192个字符为maxStringContentLength其如由错误消息中描述被超过。

但是,它可能不只是撞了所有值最大2147483647一些人建议最好的办法。

由于写的MSDN文档中,我联系:

复杂性约束提供了从拒绝服务(DOS)试图使用消息的复杂性占用端点处理资源攻击的保护。 其它复杂的约束包括诸如最大元素深度和消息中的字符串的内容的最大长度。

再加上事实,你现在有安全模式设置为 -你可能会在和自己的一些问题。



Answer 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>

不要忘了这个行为应用到端点behaviorConfiguration =“endpointbehaviour”



Answer 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>


Answer 4:

皮纳基环礁Karuri,

配额的长度不仅取决于客户端的配置 - 它们还取决于服务器的一个。 请发表您的WCF服务器的web.config,以便我们能够对这个问题提供一些线索。 还有就是你已经有配额8192设置有一个概率,所以你最快的方法是找到并增加其价值。

更新

据我所看到的,你缺少从你的服务器的web.config“readerQuotas”节点,所以MaxStringContentLength(8192)值设置为默认值。 请参考以下链接了解更多信息: http://msdn.microsoft.com/en-us/library/system.xml.xmldictionaryreaderquotas.maxstringcontentlength.aspx



Answer 5:

尝试设置下面的东西绑定。

<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/



Answer 6:

检查客户端的目标框架是相同的服务。 我有这个问题,并尝试了上述所有的修复,但没有奏效。 经过性能和检查目标框架,并改变了它。



文章来源: “The maximum string content length quota (8192) has been exceeded while reading XML data” error while sending XML string to WCF