问题
In a WCF 4.0 service we receive a huge amount of data in a generic list. This list object graph is bigger than the 65536 default limit. We are quite used to it, so we have configured the service for being able to getting those big graphs.
<serviceBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
With the above chunk of xml config we have avoided the problem in the past with no problem, but now it doesn't work. The only difference is that here we are using KnownTypes in the huge list elements that we are trying to deserialize in the WCF method.
Maybe, am I missing some special configuration for knowntypes?
回答1:
Don't forget to check client configuration.
See similar answers in How to fix MaxItemsInObjectGraph error?
You need to set the MaxItemsInObjectGraph on the dataContractSerializer using a behavior on both the client and service.
and maxItemsInObjectGraph ignored
I had forgot to place this setting in my client app.config file
.
回答2:
With reference to http://wcf.codeplex.com/discussions/258278, put the following ServiceBehavior attribute on the class definition as follows:
[ServiceContract]
[ServiceBehavior(MaxItemsInObjectGraph = int.MaxValue)]
public class MaintenanceResource
回答3:
Just as Michael said, I needed to add a behavior on my client like this (in web.config of my site):
<behavior name="deepGraph">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
...
<client>
<endpoint address="..." behaviorConfiguration="deepGraph" ... />
</client>
来源:https://stackoverflow.com/questions/9191167/maximum-number-of-items-that-can-be-serialized-or-deserialized-in-an-object-grap