4

When returning a large amount of XML data through an ASP.NET Web API service the error: HTTP Error 500 (Internal Server Error) is produced. This error is usually found when there is a circular dependency in the model but this is not the case here as the data returns perfectly when there is a smaller amount of data.

The error seems to be produced when the amount of nodes surpasses 60,000, after doing some research I found that there is a WCF parameter that limits the amount of items in an object graph, this parameter has a default value of: 65,536 is this what is causing my problem? and if so is there a way in which I can alter that value in ASP.NET Web API?

tugberk
  • 57,477
  • 67
  • 243
  • 335
  • Have you found [this article](http://www.strathweb.com/2012/09/dealing-with-large-files-in-asp-net-web-api/)? Do you know what specific error is being thrown on the server (that then produced the 500)? – Davin Tryon Jan 14 '13 at 14:33
  • Yes, but that article refers to files used as input, I am looking to increase the limit of the maximum XML output. This is essentially the problem I am having: http://forums.asp.net/t/1353779.aspx/1 but the solution posted there is for WCF whereas I am looking to do the same thing in MVC 4 Web API. – user1977490 Jan 14 '13 at 14:37
  • What is the underlying exception? – Davin Tryon Jan 14 '13 at 14:47
  • This is the only error I get: "HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request." – user1977490 Jan 14 '13 at 14:57
  • 1
    Are you using the RouteTables.Routes.MapServiceRoute in your global.asax? If yes you can create an instance of the HttpConfiguration before this and then increase the values Ex: var config = new HttpConfiguration(); config.MaxReceivedMessageSize = int.MaxValue; config.MaxBufferSize = int.MaxValue; – Rajesh Jan 14 '13 at 15:00
  • I am using RouteCollection.MapRoute(), I already have a HttpConfiguration instance but it doesn't have parameters for either 'MaxReceivedMessageSize' or 'MaxBufferSize'. – user1977490 Jan 14 '13 at 15:16
  • See http://stackoverflow.com/questions/6462571/c-sharp-wcf-web-api-4-maxreceivedmessagesize – Rolfvm Apr 08 '13 at 15:44

1 Answers1

1

Do you really need that much nodes to be returned? Maybe you should consider paging it using $top={pageSize}&$skip={pageNumber} in query. However I assume you are using [Queryable] attribute in API controller. If so you can try using MaxNodeCount property.

Adomas.NET
  • 126
  • 1
  • 4