How can I set the maxItemsInObjectGraph for the DataContractJsonSerializer?
I get an error saying "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."
Where does the number 65536 come from. The documentation for DataContractJsonSerializer says the default is Int32.MaxValue.
I tried to set it in the behavior configuration:
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
<dataContractJsonSerializer maxItemsInObjectGraph="500000"/>
</behavior>
</endpointBehaviors>
but I get an error like: "Invalid element in configuration. The extension name 'dataContractJsonSerializer' is not registered in the collection at system.serviceModel/extensions/behaviorExtensions."
Changing the behavior to <dataContractSerializer maxItemsInObjectGraph="500000"/>
gives no error but doesn't change the value (which is no surprise since I'm not using the dataContractSerializer)
The client is created with a ChannelFactory so I can't use the ServiceBehavior attribute as described here here
I don't know if you can do it via config (haven't tried), but you can increase the MaxItemsInObjectGraph property on the code, and it should work. In the example below, if I don't increase it, the call fails; otherwise it succeeds.