WCF常见异常-The maximum string content length quota (8192) has been exceeded while reading XML data

异常信息:The maximum string content length quota (8192) has been exceeded while reading XML dataui

 

问题:调用第三方的WCF服务,产生上述异常信息spa

 

分析:code

在公布WCF host端时,要确保host端以及客户端的设置容许必定大小的数据传输。blog

若是未设置传输大小,maxStringContentLength默认大小为8192。utf-8

1)若是第三方服务未设置maxStringContentLength或者设置的maxStringContentLength小于咱们调用第三方WCF服务返回的传输信息,则会产生上述异常。string

这种状况,咱们能够联系第三方将maxStringContentLength的值设置大一些。it

2)若是调用方未设置maxStringContentLength或者设置的maxStringContentLength小于咱们调用WCF服务返回的传输信息,也会产生上述异常。io

这种状况只需在咱们的配置文件中将maxStringContentLength修改成合适的大小便可class

 

解决方案:cli

首先,肯定是客户端仍是host端的限制。若是是客户端的限制,在客户端修改;若是是host端(本身项目的或者第三方的)的限制,在host端修改

而后,修改配置文件:

<binding name="服务endpoint节点对应的bindingConfiguration值" openTimeout="00:05:00" receiveTimeout="00:05:00" sendTimeout="00:05:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="655360000" maxBufferPoolSize="5242880000" maxReceivedMessageSize="655360000" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
 <readerQuotas maxDepth="320" maxStringContentLength="655360000" maxArrayLength="163840" maxBytesPerRead="40960" maxNameTableCharCount="163840" />
 <security mode="None">
 <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
 <message clientCredentialType="UserName" algorithmSuite="Default" />
 </security>
</binding>

代码:maxStringContentLength="655360000" ,须要根据WCF服务传输信息的长度自行设置。

相关文章
相关标签/搜索