WCF MaxItemsInObjectGraph setting not working

Dave picture Dave · Jul 12, 2013 · Viewed 18.1k times · Source

I have been getting the following error trying to access my WCF service.

'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

Doing some research, it looks like all I need to do is update this setting to be a higher value. This is what I am trying to do, but the setting does not seem to be getting read from the configuration. I keep getting the same exception with the 65536 value in it.

I followed the instructions found at this Link, but am having no luck.

Here is what I have configured on the WCF Service's Web.Config.

    <behaviors>
        <serviceBehaviors>
            <behavior name="metadataBehavior">
                <serviceMetadata httpGetEnabled="true"  httpGetUrl="" />
                <serviceDebug includeExceptionDetailInFaults="false" />
                <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>

This is what is in the Client's app.config:

        <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="True" />
                <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior >
                <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
            </behavior>
        </endpointBehaviors>
    </behaviors>

And lastly, I have the following attribute on the WCF service itself:

[ServiceBehavior(MaxItemsInObjectGraph = 2147483646, IncludeExceptionDetailInFaults = true)]

Despite the configurations above, I still get an Exception complaining about the 65536 value. Why aren't any of these settings being used by the applications? Is there something else that needs to be set somewhere?

Answer

SergioM picture SergioM · Jun 6, 2014

You were on the right track! All you had to do was add a name to the behavior

<behavior name="MyBehavior">
    <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
 </behavior>

And then on the end point add

<endpoint .... behaviorConfiguration="MyBehavior"/>