Thursday, May 13, 2010

Fix WCF Service MaxItemsInObjectGraph Error

The error is:

"System.Runtime.Serialization.SerializationException: Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota."

The solution is:
  • Edit the Web.Config file
  • Add the following to the <system.serviceModel><behaviors> section:
      <endpointBehaviors>

          <behavior name="exampleBehavior">
            <dataContractSerializer maxItemsInObjectGraph="200000"/>
          </behavior>

      </endpointBehaviors>

      <serviceBehaviors>

        <behavior name="exampleBehavior">
          <dataContractSerializer maxItemsInObjectGraph="200000"/>
        </behavior>

      </serviceBehaviors>
  • Change the maxItemsInObjectGraph value to whatever the maximum number of items that you need to be serialized is (usually the maximum number of records that your service returns).

No comments:

Post a Comment