Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify the default allowed response size settings for a Web API Application?

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

like image 916
The Light Avatar asked May 08 '13 09:05

The Light


People also ask

What is the default response format of a web API?

By default Web API returns result in XML format.

How to change max response size in Postman?

To do this, go to Settings > General > Max response size in MB and adjust the value to 100.

How do I send a custom response in Web API?

Implementing a custom response handler in Web API. Create a new Web API project in Visual Studio and save it with the name of your choice. Now, select the Web API project you have created in the Solution Explorer Window and create a Solution Folder. Create a file named CustomResponseHandler.

What is response type in Web API?

The XMLHttpRequest property responseType is an enumerated string value specifying the type of data contained in the response. It also lets the author change the response type. If an empty string is set as the value of responseType , the default value of text is used.


2 Answers

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.

like image 164
Toan Vo Avatar answered Sep 18 '22 05:09

Toan Vo


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> 
like image 36
Shady Mohamed Sherif Avatar answered Sep 22 '22 05:09

Shady Mohamed Sherif