C#WCF的Web阿比4 MaxReceivedMessageSize [英] C# WCF Web Api 4 MaxReceivedMessageSize

查看:126
本文介绍了C#WCF的Web阿比4 MaxReceivedMessageSize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用WCF的Web阿比4.0框架,并正在运行到maxReceivedMessageSize已经超过了65000错误。

我已经更新了我的webconfig看起来是这样,但因为我uisng的WCF的Web阿比我觉得这是不是即使再使用,因为我已经不再使用webHttpEndpoint?

 < standardEndpoints>
      < webHttpEndpoint>
        <! - 
            通过的global.asax.cs文件和默认端点配置WCF REST服务的基址
            经由上的&lt属性; standardEndpoint>下面元
         - >
        < standardEndpoint NAME =
                          helpEnabled =真
                          automaticFormatSelectionEnabled =真
                          maxReceivedMessageSize =4194304/>

      < / webHttpEndpoint>
 

我在哪里,在新的WCF的Web阿比指定MaxReceivedMessageSize?

我也尝试了CustomHttpOperationHandlerFactory无济于事:

 公共类CustomHttpOperationHandlerFactory:HttpOperationHandlerFactory
    {
        保护覆盖System.Collections.ObjectModel.Collection< HttpOperationHandler> OnCreateRequestHandlers(System.ServiceModel.Description.ServiceEndpoint终点,HttpOperationDescription操作)
        {
            VAR结合=(HttpBinding)endpoint.Binding;
            binding.MaxReceivedMessageSize = Int32.MaxValue;

            返回base.OnCreateRequestHandlers(端点操作);
        }
    }
 

解决方案

如果你想(通过使用MapServiceRoute与HttpHostConfiguration.Create)的编程方式做到这一点,你做的是这样的:

  IHttpHostConfigurationBuilder httpHostConfiguration = HttpHostConfiguration.Create(); //并添加任何配置的详细信息,你通常有

RouteTable.Routes.MapServiceRoute<为MyService,NoMessageSizeLimitHostConfig>(serviceUri分别,httpHostConfiguration);
 

该NoMessageSizeLimitHostConfig是HttpConfigurableServiceHostFactory的扩展,它看起来是这样的:

 公共类NoMessageSizeLimitHostConfig:HttpConfigurableServiceHostFactory
{
    保护覆盖ServiceHost的CreateServiceHost(类型的serviceType,乌里[] baseAddresses)
    {
        VAR主机= base.CreateServiceHost(的serviceType,baseAddresses);

        的foreach(在host.Description.Endpoints VAR端点)
        {
            VAR结合= endpoint.Binding为HttpBinding;

            如果(绑定!= NULL)
            {
                binding.MaxReceivedMessageSize = Int32.MaxValue;
                binding.MaxBufferPoolSize = Int32.MaxValue;
                binding.MaxBufferSize = Int32.MaxValue;
                binding.TransferMode = TransferMode.Streamed;
            }
        }
        返回主机;
    }
}
 

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);
        }
    }

解决方案

If you're trying to do this programatically (via using MapServiceRoute with HttpHostConfiguration.Create) the way you do it is like this:

IHttpHostConfigurationBuilder httpHostConfiguration = HttpHostConfiguration.Create(); //And add on whatever configuration details you would normally have

RouteTable.Routes.MapServiceRoute<MyService, NoMessageSizeLimitHostConfig>(serviceUri, httpHostConfiguration);  

The NoMessageSizeLimitHostConfig is an extension of HttpConfigurableServiceHostFactory that looks something like:

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;
    }
}

这篇关于C#WCF的Web阿比4 MaxReceivedMessageSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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