15

I have a Web API method that returns a list of Events:

public HttpResponseMessage GetEvents()
{
...
}

My Service supports both Xml and JSON responses using DataContractSerializer (for xml) and DataContractJsonSerializer (for JSON).

The response size might be like 30MB.

What's the default allowed response size in ASP.NET Web API hosted in IIS?

How to modify the default settings?

What's the best practice in returning such large data (though it's not that large)?

Should I zip the response?

Also, we may get one request per second.

Thanks

The Light
  • 26,341
  • 62
  • 176
  • 258

2 Answers2

14

I am not sure about your problems. Because Response have not limit the size. We can limitation the response size by add more parameter Content-Length into the response header. So I assume you will got two problems as below:

1. Request got limitation: To resolve it you should increase the request size to it can receive big size response. To increase request size you put into web.config as below:

<system.web>
<httpRuntime maxRequestLength="2147483647" />

2. You got response buffer size are limitation exception:

Please follow the link from MSDN.

EDIT:

What's the default allowed response size in ASP.NET Web API hosted in IIS?

The response size will auto get size by size of message we put into it. And it have limitation about response size. The HttpReponseMessage actually is a response similar I have posted above.

What's the best practice in returning such large data (though it's not that large)?

You should take link. The best practices to deal with data is convert to binary data and transfer it as many small-parts.

Should I zip the response?

Depends on your context. IIS 7.0 already allow you configure zip response but take care on your code at client already support zip response or not.

Community
  • 1
  • 1
Toan Vo
  • 1,270
  • 9
  • 19
9

try this code in your web.config it solved my problem

    <configuration> 
       <system.web.extensions>
           <scripting>
               <webServices>
                   <jsonSerialization maxJsonLength="50000000"/>
               </webServices>
           </scripting>
       </system.web.extensions>
    </configuration> 
Shady Mohamed Sherif
  • 15,003
  • 4
  • 45
  • 54