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
By default Web API returns result in XML format.
To do this, go to Settings > General > Max response size in MB and adjust the value to 100.
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With