2010-03-25 28 views
11

嘗試通過WCF服務傳遞DTO時,出現以下異常。WCF最大讀取深度異常

System.Xml.XmlException: The maximum read depth (32) has been exceeded because XML data being read has more levels of nesting than is allowed by the quota. This quota may be increased by changing the MaxDepth property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 5230. 
    at System.Xml.XmlExceptionHelper.ThrowXmlException 

在app.config結合看起來像這樣

<binding name="WSHttpBinding_IProjectWcfService" closeTimeout="00:10:00" 
     openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
     bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferPoolSize="524288" maxReceivedMessageSize="10240000" messageEncoding="Text" 
     textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
     <readerQuotas maxDepth="200" maxStringContentLength="8192" maxArrayLength="16384" 
     maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <reliableSession ordered="true" inactivityTimeout="00:10:00" 
     enabled="false" /> 
     <security mode="Message"> 

     <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""> 
      <extendedProtectionPolicy policyEnforcement="Never" /> 
     </transport> 
     <message clientCredentialType="UserName" negotiateServiceCredential="true" 
      algorithmSuite="Default" establishSecurityContext="true" /> 
     </security> 
    </binding> 

Web.config文件服務行爲:

而且DTO是這樣的:

[Serializable] 
[DataContract(IsReference=true)] 
public class MyDto 
{ 

任何幫助將不勝感激,因爲我用它拉我的頭髮。

+1

你改變客戶端和服務器上的配置?我有這樣的印象,我必須在兩者之前匹配這一變化。 – 2010-03-25 00:22:55

+1

非常不尋常的嵌套那很深。你可能有一個循環引用。我想我們需要看到更多的DTO;改變最大嵌套可能只是一個創可貼解決方案。 – Aaronaught 2010-03-25 02:16:43

+0

我解決了我的問題,因爲我在這裏解釋:http://stackoverflow.com/questions/5537794/error-while-deserializing-the-object-in-wcf – Adi 2011-12-07 13:18:16

回答

21

有一個設置叫maxDepth<readerQuotas>你應該能夠設定爲較高的值大於32(默認)。你顯然已經在客戶端上設置了這個參數(maxDepth = 200),但是你也需要在服務器端做這個 - 否則,這兩個值中較小的一個(在客戶端和服務器之間)將定義實際使用的數字。

確保你的服務器端還包括在其配置的wsHttpBinding這些行:

<readerQuotas maxDepth="200" maxStringContentLength="8192" maxArrayLength="16384" 
     maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
+1

我有同樣的問題,我解決了它通過使用此解決方案!謝謝.. – 2013-11-13 05:41:21

+0

readerQuotas是綁定的節點。所以在web.config應該是這樣的: \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 2017-08-15 11:04:36

5

你必須改變客戶端和服務器同時匹配上綁定配置...