Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
XML
<readerQuotas maxDepth="200" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

My Service Configuration:
XML
<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:
XML
<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>
Also, I have added maxRequestLength in httpRuntime both in client and service config
XML
<system.web>
    <httpRuntime targetFramework="4.6" maxRequestLength="2147483646"/>
</system.web>
Posted
Updated 14-Jun-18 6:59am

1 solution

Quote:
The maximum read depth (200) has been exceeded ...
<readerQuotas maxDepth="200" ...

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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900