我得到了以下错误:
The maximum message size quota for incoming messages (65536) has been exceeded.
To increase the quota, use the MaxReceivedMessageSize property on
the appropriate binding element.需要帮助流超过65536字节。
有没有办法编辑ServiceHostFactory行为,以便在某个地方将MaxReceivedMessageSize属性设置为2GB
谢谢你的回应。
由于我使用的是WebHttpBinding,所以我想知道如何覆盖ServiceHostFactory。
创建自定义类并重写WebServiceHost的OnOpening()方法可以解决这个问题吗?
发布于 2012-05-20 03:36:53
MaxReceivedMessageSize是绑定元素的一个属性;如果需要将其从默认值中更改,则有两个选项:
binding元素中设置它。要在客户端执行此操作,不需要配置文件,您需要绕过正常的服务引用代码,自己创建客户端通道。您可以在我的博客文章中看到如何使用WCF而不使用自动生成的客户端代理的示例:无代理WCF。本质上,您可以在代码中执行类似的操作:
var binding = new WebHttpBinding();
binding.MaxReceivedMessageSize = int.MaxValue;
var factory = new ChannelFactory<IServiceInterfaceChannel>(binding);
var client = factory.CreateChannel(new Endpoint(SERVICE_URL));如果需要更改服务端的行为,可以通过调用服务主机类上的AddServiceEndpoint来指定绑定,例如:
var host = new WebServiceHost();
var binding = new WebHttpBinding();
binding.MaxReceivedMessageSize = int.MaxValue;
host.AddServiceEndpoint(typeof(IServiceInterface), binding, SERVICE_URL);此外,我认为您可以按照您的问题,通过重写自定义web服务主机的OnOpening方法来实现这一点。请注意,基本OnOpening行为可能会创建端点和编辑绑定行为,因此在您尝试自己更改绑定配置之前,您将希望让它先完成所有这些操作。但我不知道你为什么要这么麻烦.
发布于 2015-01-14 05:19:05
最简单的方法是在web.config中配置它,如果需要,可以稍后对其进行更改。首先创建绑定配置,如下所示,在web.config或app.config中
<bindings>
<basicHttpBinding>
<webHttpBinding>
<binding name="Binding_Name" maxReceivedMessageSize="2147483647">
</binding>
</webHttpBinding>
</bindings>然后在服务端点中提到相同的内容,如下所述
<services>
<service behaviorConfiguration="ServiceBehaviour" name="Servicename">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="Binding_Name" contract="Contractname" />
</service>
</services>https://stackoverflow.com/questions/10667895
复制相似问题