C#WCF Web Api 4 MaxReceivedMessageSize

前端之家收集整理的这篇文章主要介绍了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);
        }
    }

解决方法

如果您尝试以编程方式执行此操作(通过使用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;
    }
}
原文链接:https://www.f2er.com/c/110980.html

猜你在找的C&C++相关文章