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

查看:250
本文介绍了如何修改为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.

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

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.

感谢

推荐答案

我不知道你的问题。因为响应没有限制的大小。我们可以不限响应大小通过增加更多的参数的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 如下:

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

2。你得到了响应缓冲区大小有限制的例外:

请遵循MSDN的链接

编辑:

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

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

响应大小由消息的大小自动获取大小,我们把它付诸表决。它有关于响应大小限制。在的Htt preponseMessage 其实就是一个类似的反应我已经张贴以上。

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)?

您应该采取<一个href=\"http://stackoverflow.com/questions/9541351/returning-binary-file-from-controller-in-asp-net-web-api\">link.处理数据的最佳做法是转换为二进制数据,并将其传递尽可能多的小部分。

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已经允许你配置压缩响应,但照顾你的code。在客户端已经支持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天全站免登陆