8

I am having issues specifying the dataContractSerializer maxItemsInObjectGraph in host's web.config.

 <behaviors>
  <serviceBehaviors>
    <behavior name="beSetting">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="True" />
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
 <services>
  <service name="MyNamespace.MyService"
           behaviorConfiguration="beSetting" >
    <endpoint address="http://localhost/myservice/"
              binding="webHttpBinding"
              bindingConfiguration="webHttpBinding1"
              contract="MyNamespace.IMyService"
              bindingNamespace="MyNamespace">
    </endpoint>
  </service>
</services>

The above has no effect on my data pull. The server times out because of the large volume of data.

I can however specify the max limit in code and that works

  [ServiceBehavior(MaxItemsInObjectGraph=2147483646, IncludeExceptionDetailInFaults = true)]
  public abstract class MyService : MyService 
  {
   blah...
 }

Does anyone know why I can't make this work through a web.config setting? I would like to keep in the web.config so it is easier for future updates.

Dave
  • 4,038
  • 9
  • 45
  • 57
  • I'm having this problem too. I wonder why no one else has answered? Thanks for the tip about being able to set the `ServiceBehavior` in code, it may at least get me moving. – jocull Jul 05 '11 at 06:00
  • You know that maxItemsInObjectGraph only defines the total number of permitted elements in the response, not the outright response size yeah? (i think if it's not specified it defaults to 60k xml elements) – Nick Ryan Aug 10 '11 at 14:42
  • Dave, was your question answered or not? If the given answer solved your problem, mark it as so. – Bardia Dec 17 '12 at 19:56

1 Answers1

12

In your behavior section, add an endpoint behavior with the dataContractSerializer, like so:

<endpointBehaviors>
  <behavior name="LargeQuotaBehavior">
   <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
  </behavior>
</endpointBehaviors>

Then modify your endpoint to use this behavior like so:

<endpoint address="http://localhost/myservice/"
          binding="webHttpBinding"
          bindingConfiguration="webHttpBinding1"
          contract="MyNamespace.IMyService"
          bindingNamespace="MyNamespace"
          behaviorConfiguration="LargeQuotaBehavior">

This should solve your problem.

Bardia
  • 317
  • 4
  • 9
  • 1
    I ran into a similar issue today. Wcf was throwing exceptions about maxItemsInObjectGraph exceeded even though it was there in endpoint behaviour. then I moved that to Service behaviour which solved the issue.http://stackoverflow.com/questions/26610861/passing-comma-separated-string-value-to-a-wcf-rest-service/26613810#26613810 – user1131926 Oct 28 '14 at 17:04