C#WCF Web Api 4 MaxReceivedMessageSize
发布时间:2020-12-16 03:34:52 所属栏目:百科 来源:网络整理
导读:我正在使用WCF Web Api 4.0框架,并且运行到maxReceivedMessageSize已超过65,000错误. 我已经更新了我的webconfig看起来像这样,但因为我使用WCF Web Api我认为这已不再使用,因为我不再使用webHttpEndpoint了? standardEndpoints webHttpEndpoint !-- Configu
|
我正在使用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);
}
}
解决方法
如果您尝试以编程方式执行此操作(通过使用MapServiceRoute和HttpHostConfiguration.Create),则执行此操作的方式如下:
IHttpHostConfigurationBuilder httpHostConfiguration = HttpHostConfiguration.Create(); //And add on whatever configuration details you would normally have RouteTable.Routes.MapServiceRoute<MyService,NoMessageSizeLimitHostConfig>(serviceUri,httpHostConfiguration); NoMessageSizeLimitHostConfig是HttpConfigurableServiceHostFactory的扩展,类似于: public class NoMessageSizeLimitHostConfig : HttpConfigurableServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType,Uri[] baseAddresses)
{
var host = base.CreateServiceHost(serviceType,baseAddresses);
foreach (var endpoint in host.Description.Endpoints)
{
var binding = endpoint.Binding as HttpBinding;
if (binding != null)
{
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.MaxBufferPoolSize = Int32.MaxValue;
binding.MaxBufferSize = Int32.MaxValue;
binding.TransferMode = TransferMode.Streamed;
}
}
return host;
}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
