简体   繁体   English

超出WebHttpBinding消息大小配额

[英]WebHttpBinding message size quota exceeded

I am getting the following error: 我收到以下错误:

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.
  1. I am using WebhttpBinding which uses REST service. 我正在使用使用REST服务的WebhttpBinding。
  2. There is no configuration setting from client side. 客户端没有配置设置。
  3. I am using MVC3 application. 我正在使用MVC3应用程序。

Need help in stream more than 65536 bytes. 流需要超过65536字节的帮助。

Is there any way to edit the ServiceHostFactory behaviour so that somewhere I can set MaxReceivedMessageSize property to 2GB 有没有办法编辑ServiceHostFactory行为,以便我可以将MaxReceivedMessageSize属性设置为2GB


thanks for your response. 感谢您的答复。

Since I am using WebHttpBinding,I would like to know how to override the ServiceHostFactory . 由于我使用WebHttpBinding,我想知道如何覆盖ServiceHostFactory。

Creating a custom class and overriding the OnOpening() method of WebServiceHost can resolve the problem or not? 创建自定义类并重写WebServiceHost的OnOpening()方法可以解决问题吗?

MaxReceivedMessageSize is a property of the binding element; MaxReceivedMessageSize是绑定元素的属性; if you need to change it from the defaults you have two options: 如果您需要从默认值更改它,您有两个选择:

  1. Use a configuration file, and set it from within a binding element. 使用配置文件,并从binding元素中进行设置。
  2. Create the bindings in code and set the property there. 在代码中创建绑定并在那里设置属性。

To do this on the client side, without a configuration file, you'll need to bypass the normal service reference code and create the client channel yourself. 要在客户端执行此操作,不使用配置文件,您需要绕过正常的服务引用代码并自行创建客户端通道。 You can see an example of how to do this on my blog post about using WCF without the auto-generated client proxy: Proxy-Free WCF . 您可以在我的博客文章中看到有关如何在没有自动生成的客户端代理的情况下使用WCF的示例:无代理WCF In essence, you do something like this in code: 实质上,您在代码中执行以下操作:

var binding = new WebHttpBinding();
binding.MaxReceivedMessageSize = int.MaxValue;

var factory = new ChannelFactory<IServiceInterfaceChannel>(binding);
var client = factory.CreateChannel(new Endpoint(SERVICE_URL));

If you need to change the behavior on the service side, you can specify a binding by calling AddServiceEndpoint on the service host class, for example: 如果需要更改服务端的行为,可以通过在服务主机类上调用AddServiceEndpoint来指定绑定,例如:

var host = new WebServiceHost();
var binding = new WebHttpBinding();
binding.MaxReceivedMessageSize = int.MaxValue;

host.AddServiceEndpoint(typeof(IServiceInterface), binding, SERVICE_URL);

Also, I think that you could accomplish this by overriding the OnOpening method of a custom web service host, as per your question. 此外,我认为您可以通过覆盖自定义Web服务主机的OnOpening方法来完成此操作,根据您的问题。 Be aware that the base OnOpening behavior potentially creates endpoints and edits binding behavior, so you will want to let it do all of that first, before you try to change the binding configurations yourself. 请注意,基于OnOpening行为可能会创建端点和编辑绑定行为,因此在尝试自行更改绑定配置之前,您需要先让它完成所有这些操作。 But I'm not really sure why you would go to all that trouble... 但我不确定你为什么要去那么麻烦......

Easiest way is to configure it in web.config where you can change it later if needed. 最简单的方法是在web.config中配置它,您可以在以后根据需要进行更改。 First create binding configuration as mentioned below in your web.config or app.config 首先在web.config或app.config中创建如下所述的绑定配置

 <bindings>
   <basicHttpBinding>
    <webHttpBinding>
    <binding name="Binding_Name" maxReceivedMessageSize="2147483647">
    </binding>
   </webHttpBinding>
  </bindings>

Then mention the same in your service endpoint as written below 然后在服务端点中提及相同内容,如下所示

<services>
<service behaviorConfiguration="ServiceBehaviour" name="Servicename">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="Binding_Name" contract="Contractname" />
</service>
</services>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WCF MaxReceivedMessageSize:超出最大邮件大小配额 - WCF MaxReceivedMessageSize: maximum message size quota exceeded 已超出传入邮件的最大邮件大小配额 (65536) - The maximum message size quota for incoming messages (65536) has been exceeded 是否超过了传入消息的最大消息大小配额(65536)? - The maximum message size quota for incoming messages (65536) has been exceeded? 已超出传入邮件的最大邮件大小配额例外 - Maximum Message Size quota for Incoming messages has been exceeded exception 超出了传入邮件的最大邮件大小配额(65536) - The maximum message size quota for incoming messages (65536) has been exceeded 已超出传入邮件的最大邮件大小限额(65536) - The maximum message size quota for incoming messages (65536) has been exceeded 已超出传入邮件的最大邮件大小配额 (65536) - maximum message size quota for incoming messages (65536) has been exceeded 已超出传入邮件的最大邮件大小限额(65536) - The maximum message size quota for incoming messages (65536) has been exceeded WCF - 已超出传入邮件的最大邮件大小配额 - WCF - The maximum message size quota for incoming messages has been exceeded 在远程计算机上的WCF netTcpBinding上超出了邮件大小配额 - Message size quota exceeded on WCF netTcpBinding in remote machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM