6

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?

Pablo Castilla
  • 2,723
  • 2
  • 28
  • 33
  • And you are certain that its the MaxItemsInObjectGraph that's being exceeded and not, for example, the MaxReceivedMessageSize? – Richard Blewett Feb 08 '12 at 14:01
  • the exception is clear 'Maximum number of items that can be serialized or deserialized in an object graph is '65535' :( – Pablo Castilla Feb 08 '12 at 14:49
  • Does your service declare a behaviorConfiguration attribute? If so it won't pick up the default one above – Richard Blewett Feb 08 '12 at 20:00
  • In my tests and in other services it does, but I will try defining everything. – Pablo Castilla Feb 09 '12 at 07:43
  • The behavior block you show above is unnamed - in .NET 4 this will act as a default for any services that do not explicitly declare a behaviorConfiguration. If your service does (to, for example, expose metadata) then this change to the maxItemsInObjectGraph will not be picked up – Richard Blewett Feb 09 '12 at 10:25

3 Answers3

9

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

.

Community
  • 1
  • 1
Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
1

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
D Barndon
  • 11
  • 2
  • In production it is recommended to specify real expected value,rather then MaxValue, and config file is a flexible option, but attribute is not flexible. – Michael Freidgeim Jun 04 '13 at 09:16
0

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>
Björn
  • 3,098
  • 2
  • 26
  • 40