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服務傳輸信息的長度自行設置。

相關文章
相關標籤/搜索