C# WCF Web Api 4 MaxReceivedMessageSize
我正在使用 WCF Web Api 4.0 框架,并且遇到 maxReceivedMessageSize 已超过 65,000 错误。
我已经将我的 webconfig 更新为如下所示,但因为我正在使用 WCF Web Api,我认为这甚至不再使用,因为我不再使用 webHttpEndpoint?
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name=""
helpEnabled="true"
automaticFormatSelectionEnabled="true"
maxReceivedMessageSize="4194304" />
</webHttpEndpoint>
在新的 WCF Web Api 中,我在哪里指定 MaxReceivedMessageSize?
我也尝试过 CustomHttpOperationHandlerFactory,但无济于事:
public class CustomHttpOperationHandlerFactory: HttpOperationHandlerFactory
{
protected override System.Collections.ObjectModel.Collection<HttpOperationHandler> OnCreateRequestHandlers(System.ServiceModel.Description.ServiceEndpoint endpoint, HttpOperationDescription operation)
{
var binding = (HttpBinding)endpoint.Binding;
binding.MaxReceivedMessageSize = Int32.MaxValue;
return base.OnCreateRequestHandlers(endpoint, operation);
}
}
I am using the WCF Web Api 4.0 framework and am running into the maxReceivedMessageSize has exceeded 65,000 error.
I've updated my webconfig to look like this but because I am uisng the WCF Web Api I think this isn't even used anymore as I am no longer using a webHttpEndpoint?
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name=""
helpEnabled="true"
automaticFormatSelectionEnabled="true"
maxReceivedMessageSize="4194304" />
</webHttpEndpoint>
Where do I specify MaxReceivedMessageSize in the new WCF Web Api?
I've also tried a CustomHttpOperationHandlerFactory to no avail:
public class CustomHttpOperationHandlerFactory: HttpOperationHandlerFactory
{
protected override System.Collections.ObjectModel.Collection<HttpOperationHandler> OnCreateRequestHandlers(System.ServiceModel.Description.ServiceEndpoint endpoint, HttpOperationDescription operation)
{
var binding = (HttpBinding)endpoint.Binding;
binding.MaxReceivedMessageSize = Int32.MaxValue;
return base.OnCreateRequestHandlers(endpoint, operation);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
maxReceivedMessageSize 是您必须在正在使用的绑定上定义的属性。 .Net 4 中的 WCF 引入了简化的配置,因此如果您不配置任何内容,将使用默认值。
下面的示例对于 wshttpBinding 有效,您可以根据您使用的绑定对其进行修改,并将其注册到 web.config 中的 servicemodel-binding 部分(假设您使用的是 IIS 托管服务)。
华泰
多米尼克
the maxReceivedMessageSize is a property you have to define on the binding you´re using. WCF in .Net 4 introduced the simplified configuration, so if you don´t configure anything, default values will be used.
The example below is valid for the wshttpBinding, you have the ammend it according to your used binding and register it in your web.config (assuming you´re using an IIS hosted service) in the servicemodel-binding section.
HTH
Dominik
如果您尝试以编程方式执行此操作(通过将 MapServiceRoute 与 HttpHostConfiguration.Create 结合使用),则执行方式如下:
NoMessageSizeLimitHostConfig 是 HttpConfigurableServiceHostFactory 的扩展,如下所示:
If you're trying to do this programatically (via using MapServiceRoute with HttpHostConfiguration.Create) the way you do it is like this:
The NoMessageSizeLimitHostConfig is an extension of HttpConfigurableServiceHostFactory that looks something like:
如果您在 IIS 中托管,则可以在定义路由的位置设置值(在我的例子中为 global.asax)。如果您将
TransferMode
设置为缓冲(默认),则还需要将MaxBufferSize
设置为与MaxReceivedMessageSize
相同的值。If you are hosting in IIS, you can set the values where ever you define the route (in my case, the global.asax). If you have
TransferMode
set to buffered (the default), you will also need to setMaxBufferSize
to the same value asMaxReceivedMessageSize
.这是在代码中执行此操作的方法。
如果您创建自己的自定义主机(从标准主机派生),则可以重载一种方法来配置 HttpEndpoint。
This is how you can do it in code
If you create a your own custom host, derived from the standard one, there is a method that you can overload to configure the HttpEndpoint.