Response for REST method was truncated because default MaxItemsInObjectGraph was not big enough.

We have a   REST service with attributes [WebGet(UriTemplate ="...", BodyStyle =WebMessageBodyStyle.Bare, ResponseFormat =WebMessageFormat.Xml)]

Normally it worked fine. But for particular data it has a huge response that was truncated. 

The size returned in a few attempts in IE browser was 2196456, in Chrome slightly different 2195397.

After a search in google I found http://forums.asp.net/post/4948029.aspx, that has a number of suggestions.

For WCF service that will transfer large amount of data in operations, here are the configuration settings you need to check:

  1. the maxReceivedMessageSize attribute of the certain element(in your case, that's the webHttpbinding)

# 
http://msdn.microsoft.com/en-us/library/bb412176.aspx

  1. The settings (under the elements) which has control over the maxarrayLength, maxStringLength ,etc...

# 
http://msdn.microsoft.com/en-us/library/ms731325.aspx

  1. The DataContractSerializer behavior which has a MaxItemsInObjectGraph property. You can configure it via ServiceBehavior of your WCF service

#DataContractSerializer.MaxItemsInObjectGraph Property 
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.maxitemsinobjectgraph.aspx

  1. And if your WCF service is hosted in ASP.NET/IIS web application, you also need to enlarge the "maxRequestLength" attribute of the element (under <system.web> section).

#httpRuntime Element (ASP.NET Settings Schema) 
http://msdn.microsoft.com/en-us/library/e1f13641.aspx

 After a few attempts my collegue found that our problem was caused by

#DataContractSerializer.MaxItemsInObjectGraph Property 
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.maxitemsinobjectgraph.aspx

<behavior name="MyOperationBehavior">

          < dataContractSerializer maxItemsInObjectGraph ="2196456" />

</behavior>

This article is part of the GWB Archives. Original Author: Michael Freidgeim

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.