将对象发送到WCF服务时的最大读取深度问题 [英] Max read depth issue when sending objects to WCF service

查看:70
本文介绍了将对象发送到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绑定

I am getting the below exception while sending objects to the WCF service, could anyone help me out to resolve this issue.

Exception:
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:xxxx(class object). The InnerException message was 'There was an error deserializing the object of xxxxx.xx.xxx.xxxx(class). The maximum read depth (200) 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 2, position 59349.'. Please see InnerException for more details.

Inner Exception:
The maximum read depth (200) 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 2, position 59349.

What I have tried:

I have tried by setting the below readerQuotas in bindings both in client and server

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



我的服务配置:


My Service Configuration:

<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>



我的客户端配置:


My Client Configuration:

<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

Also, I have added maxRequestLength in httpRuntime both in client and service config

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

推荐答案

引用:

已超出最大读取深度(200)...

The maximum read depth (200) has been exceeded ...

<readerQuotas maxDepth="200" ...



错误告诉你 maxDepth 设置为200,这还不够。



您需要将 maxDepth 设置为更高的值。



但是,这似乎是一个在WCF请求中发送的可笑深度嵌套的对象图。你应该仔细检查你发送的数据,看看你是否可以减少深度。



例如,如果你发送链表,那么对象图表将与列表中的项目数一样深。如果您将其转换为常规的列表< T> 或数组,则对象图将是平的。


The error is telling you that the maxDepth is set to 200, and that isn't enough.

You need to set maxDepth to a higher value.

However, that seems like a ridiculously deeply nested object graph to send in a WCF request. You should double-check the data you're sending, to see if you can reduce the depth.

For example, if you were sending a linked list, the object graph would be as deep as the number of items in your list. If you converted it to a regular List<T>, or an array, then the object graph would be flat.


这篇关于将对象发送到WCF服务时的最大读取深度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆