maxItemsInObjectGraph limit required to be changed for server and client
Posted
by Michael Freidgeim
on Geeks with Blogs
See other posts from Geeks with Blogs
or by Michael Freidgeim
Published on Sun, 28 Oct 2012 11:02:09 GMT
Indexed on
2012/10/28
5:04 UTC
Read the original article
Hit count: 186
Filed under:
We have a wcf service, that expects to return a huge XML data. It worked ok in testing, but in production it failed with error
v
"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 MSDN article about dataContractSerializer xml configuration element correctly describes maxItemsInObjectGraph attribute default as 65536, but documentation for of the
DataContractSerializer.MaxItemsInObjectGraph property and DataContractJsonSerializer.MaxItemsInObjectGraph Property
are talking about Int32.MaxValue, which causes confusion, in particular because Google shows properties articles before configuration articles.
When we changed the value in WCF service configuration, it didn't help, because the similar change must be ALSO done on client.
There are similar posts:
You need to set the MaxItemsInObjectGraph on the dataContractSerializer using a behavior on both the client and service. See for an example.http://devlicio.us/blogs/derik_whittaker/archive/2010/05/04/setting-maxitemsinobjectgraph-for-wcf-there-has-to-be-a-better-way.aspx
I had forgot to place this setting in my client app.config file.
http://stackoverflow.com/questions/5867304/datacontractjsonserializer-and-maxitemsinobjectgraph?rq=1 -
It seems that DataContractJsonSerializer.MaxItemsInObjectGraph has actual default 65536, because there is no configuration for JSON serializer, but it complains about the limit.
I believe that MS should clarify the properties documentation re default limit and make more specific error messages to distinguish server side and client side errors.
Note, that as a workaround it's possible to use
commonBehaviors
section which can be defined only in machine.config:<commonBehaviors>
<behaviors>
<endpointBehaviors>
<dataContractSerializer maxItemsInObjectGraph="..." />
</endpointBehaviors>
</behaviors>
</commonBehaviors>
v
© Geeks with Blogs or respective owner