将对象发送到WCF服务时的最大读取深度问题

时间:2018-06-13 17:50:56

标签: wcf

我在向WCF服务发送对象时遇到以下异常,任何人都可以帮我解决此问题。

例外: 格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数http://tempuri.org/:xxxx(class对象时出错。 InnerException消息是'反序列化xxxxx.xx.xxx.xxxx(类)的对象时出错。已超出最大读取深度(200),因为正在读取的XML数据具有比配额允许的更多嵌套级别。通过更改创建XML阅读器时使用的XmlDictionaryReaderQuotas对象的MaxDepth属性,可以增加此配额。第2行,位置59349.'。有关详细信息,请参阅InnerException。

内部例外: 已超出最大读取深度(200),因为正在读取的XML数据具有比配额允许的更多嵌套级别。通过更改创建XML阅读器时使用的XmlDictionaryReaderQuotas对象的MaxDepth属性,可以增加此配额。第2行,第59349号。

我试过在客户端和服务器的绑定中设置以下readerQuotas

<readerQuotas maxDepth="200" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

我的服务配置:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <bindings>
      <basicHttpBinding>
        <binding name="secureHttpBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="200" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="mexBehavior" name="Service">
        <endpoint address="Service" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding" contract="IService"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/Service"/>
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

我的客户端配置:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="200" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:50259/Service.svc/Service"
        behaviorConfiguration="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
        contract="IService" name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>

另外,我在httpRuntime中添加了maxRequestLength,包括客户端和服务配置

<system.web>
    <httpRuntime targetFramework="4.6" maxRequestLength="2147483646"/>
</system.web>

0 个答案:

没有答案