Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF MaxItemsInObjectGraph setting not working

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?

like image 404
Dave Avatar asked Jul 12 '13 19:07

Dave


2 Answers

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"/>
like image 85
SergioM Avatar answered Nov 14 '22 19:11

SergioM


Had to go nuclear and update that machine.config;

Directions Here

The gist of it is to add the following to the "system.serviceModel" section.

    <commonBehaviors>
      <endpointBehaviors>
        <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      </endpointBehaviors>
      <serviceBehaviors>
         <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      </serviceBehaviors>
    </commonBehaviors>
like image 20
Dave Avatar answered Nov 14 '22 21:11

Dave