【问题标题】:WCF Maximum Read Depth ExceptionWCF 最大读取深度异常
【发布时间】:2010-03-25 00:17:40
【问题描述】:

尝试通过 WCF 服务传递 DTO 时出现以下异常。

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 服务行为:

    <behavior name="BehaviorConfiguration" >
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <dataContractSerializer maxItemsInObjectGraph="6553600" />
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="SqlRoleProvider" />
      <serviceCredentials>
        <serviceCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" />

        <userNameAuthentication userNamePasswordValidationMode="MembershipProvider" membershipProviderName="SqlMembershipProvider"/>
      </serviceCredentials>
    </behavior>

DTO 看起来像这样:

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

任何帮助都将不胜感激,因为我正在用它拉头发。

【问题讨论】:

  • 您是否更改了客户端和服务器上的配置?我的印象是我之前必须在他们两个上匹配这个更改。
  • 嵌套那么深是很不寻常的。您可能有一个循环引用。我认为我们需要看到更多的 DTO;改变最大嵌套可能只是一个创可贴的解决方案。
  • 我解决了我在这里解释的问题:stackoverflow.com/questions/5537794/…

标签: wcf web-services


【解决方案1】:

&lt;readerQuotas&gt; 上有一个名为 maxDepth 的设置,您应该可以将其设置为高于 32(默认值)的值。您显然已经在客户端上设置了这个(maxDepth=200),但您还需要在服务器端执行此操作 - 否则,两个值中较小的一个(在客户端和服务器之间)将定义使用的实数。

确保您的服务器端也在其 wsHttpBinding 配置中包含这些行:

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

【讨论】:

  • readerQuotas 是一个绑定节点。所以 web.config 应该是这样的:
【解决方案2】:

您必须更改客户端和服务器上的绑定配置以匹配...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 2012-03-12
    相关资源
    最近更新 更多