Fixing MaxItemsInObjectGraph quota Error in WCF Service

I have a WCF Service that occasionally yields a message like this one:

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.

Today isn’t the first time I’ve run into this message – I’ve fixed this issue before – but since this is the 2nd or more time I’ve run into it, I thought I’d post a quick resolution here so I can find it again later myself, and perhaps help some others.  There’s a rather long forum thread on this subject that ultimately includes the solution, but digging it out is a bit painful as is the case with so many forum threads, so I’ll sum up here and just give you what you need.

First, you need to realize that to resolve this issue you will need configuration elements to be specified on both the client and the server.  In both cases, the configuration you are looking for is going to be in a named <behavior> as part of a <dataContractSerializer> element.  Your service’s configuration might look like this:

                <behavior name="DefaultBehavior" MaxItemsInObjectGraph="2147483647">
                    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
            <service behaviorConfiguration="DefaultBehavior" name="MyService">
                <endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyService" contract="IMyService">
                        <dns value="localhost" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

I notice that my <behavior /> specifies a MaxItemsInObjectGraph value but I don’t know that that is necessary.  I’ve left it here since it’s what I actually have working in production, but the solution I found online only indicates the need for the dataContractSerializer maxItemsInObjectGraph (note case) value.  For the client, the configuration should look like this:

        <behavior name="ClientBehavior">
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>

      <endpoint address=http://localhost/MyService.svc
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyServiceConfiguration"
        contract="ServiceReferences.IMyService" name="WSHttpBinding_MyService"
          <dns value="localhost" />

Once you have these beautiful and extremely intuitive blocks of user-friendly XML in place, your WCF stuff should magically work again with larger than 65536 object graph sizes!  Enjoy!

  • Lance


    What happens if your ObjectGraph happens to be 2147483647 + 1 objects ?

  • Steve Smith


    An exception.

  • Lance

    Hi Steve!

    What’s the best way to unlimit the transfer of data, back and forth?

    I’m using buffered transfer now, what about streamed transfer, can that unlimit the transfer size?

  • Ravi

    Thanks it reall ysolved my problem

  • Nimi


  • Elodie

    Put the name of the behavior in the endpoint! That’s the detail I forgot !!!! Thanks Steve.

  • sukhi

    Hi, Its worked finse at first glance but after 2-3 runs I’m getting

    An error occurred while receiving the HTTP response to http://localohost/HistoryServiceWCF/HistoryServiceWCF.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

    Inner exception is The underlying connection was closed: An unexpected error occurred on a receive.

    any idea what is causing this… Please reach me @

  • Ashu

    Thanks a lot. This solution worked for me