2010-03-25 71 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

你必须改变客户端和服务器同时匹配上绑定配置...