代码之家  ›  专栏  ›  技术社区  ›  Burt

WCF最大读取深度异常

  •  11
  • Burt  · 技术社区  · 14 年前

    当试图通过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
    {
    

    如果我能帮上忙,我会非常感激的。

    2 回复  |  直到 14 年前
        1
  •  21
  •   marc_s Anurag    14 年前

    有一个叫 maxDepth <readerQuotas> 您应该能够将其设置为大于32的值(默认值)。显然,您已经在客户机上设置了这个值(设置为maxdepth=200),但是您还需要在服务器端进行设置—否则,两个值(客户机和服务器之间)中的较小值将定义使用的实数。

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

    <readerQuotas maxDepth="200" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    
        2
  •  5
  •   Joel Martinez    14 年前

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