Fixing MaxItemsInObjectGraph quota Error in WCF Service

Posted by: Steven Smith, on 28 Apr 2011 | View original | Bookmarked: 0 time(s)

I have a WCF Service that occasionally yields a message like this one:

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.

Today isnt the first time Ive run into this message Ive fixed this issue before but since this is the 2nd or more time Ive run into it, I thought Id post a quick resolution here so I can find it again later myself, and perhaps help some others.  Theres a rather long forum thread on this subject that ultimately includes the solution, but digging it out is a bit painful as is the case with so many forum threads, so Ill sum up here and just give you what you need.

First, you need to realize that to resolve this issue you will need configuration elements to be specified on both the client and the server.  In both cases, the configuration you are looking for is going to be in a named <behavior> as part of a <dataContractSerializer> element.  Your services configuration might look like this:

<system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="DefaultBehavior" MaxItemsInObjectGraph="2147483647">
                    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service behaviorConfiguration="DefaultBehavior" name="MyService">
                <endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyService" contract="IMyService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
         </services>
    </system.serviceModel>

I notice that my <behavior /> specifies a MaxItemsInObjectGraph value but I dont know that that is necessary.  Ive left it here since its what I actually have working in production, but the solution I found online only indicates the need for the dataContractSerializer maxItemsInObjectGraph (note case) value.  For the client, the configuration should look like this:

<system.serviceModel>
    <behaviors>
    <endpointBehaviors>
        <behavior name="ClientBehavior">
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
    </endpointBehaviors>
    </behaviors>

    <client>
      <endpoint address=http://localhost/MyService.svc
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyServiceConfiguration"
        contract="ServiceReferences.IMyService" name="WSHttpBinding_MyService"
        behaviorConfiguration="ClientBehavior">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

Once you have these beautiful and extremely intuitive blocks of user-friendly XML in place, your WCF stuff should magically work again with larger than 65536 object graph sizes!  Enjoy!


Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: WCF | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 811 | Hits: 18

Similar Posts

  • Deleting All Records In a Table EXCEPT For the N Most Recently Added Records more
  • Exporting SWF & FLV format reports in SSRS 2005 and 2008 more
  • Take Two: A jQuery WCF/ASMX ServiceProxy Client more
  • Part 3: Accessing Security and Authentication in Silverlight using .NET RIA Services. more
  • CI and Configurable Service Installers more
  • WCF defaults stifles loose coupling more
  • Do we have an Active SOA Service? more
  • Patterns: What is .net RIA Services? more
  • Validation - Part 3 - Server-Side more
  • IIS 7 Error Pages taking over 500 Errors more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD