Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

c# - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...