Maximum number of items that can be serialized or deserialized in an object graph… with knowtypes

跟風遠走 提交于 2019-12-23 09:33:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!