如何修改 Web API 应用程序的默认允许响应大小设置? [英] How to modify the default allowed response size settings for a Web API Application?

查看:23
本文介绍了如何修改 Web API 应用程序的默认允许响应大小设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回事件列表的 Web API 方法:

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

public HttpResponseMessage GetEvents()
{
...
}

我的服务使用 DataContractSerializer(用于 xml)和 DataContractJsonSerializer(用于 JSON)支持 Xml 和 JSON 响应.

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

响应大小可能是 30MB.

The response size might be like 30MB.

在 IIS 中托管的 ASP.NET Web API 中允许的默认响应大小是多少?

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

如何修改默认设置?

返回如此大的数据(虽然不是那么大)的最佳做法是什么?

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

我应该压缩回复吗?

此外,我们可能每秒收到一个请求.

Also, we may get one request per second.

谢谢

推荐答案

我不确定您的问题.因为Response 没有限制大小.我们可以通过在响应头中添加更多参数 Content-Length 来限制响应大小.所以我假设你会遇到以下两个问题:

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.请求受到限制:要解决它,您应该增加请求大小以使其可以接收大尺寸响应.要增加您放入 web.config 的请求大小,如下所示:

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.您得到响应缓冲区大小限制例外:

请访问 MSDN 中的链接.

Please follow the link from MSDN.

托管在 ASP.NET Web API 中的默认允许响应大小是多少IIS?

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

响应大小将根据我们放入其中的消息大小自动获取大小.并且它对响应大小有限制.HttpReponseMessage 实际上是一个类似于我上面发布的响应.

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.

我应该压缩回复吗?

取决于您的上下文.IIS 7.0 已经允许您配置 zip 响应,但请注意您的客户端代码是否已经支持 zip 响应.

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.

这篇关于如何修改 Web API 应用程序的默认允许响应大小设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆