Reputation: 1943
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.
Need help in stream more than 65536 bytes.
Is there any way to edit the ServiceHostFactory behaviour so that somewhere I can set MaxReceivedMessageSize property to 2GB
thanks for your response.
Since I am using WebHttpBinding,I would like to know how to override the ServiceHostFactory .
Creating a custom class and overriding the OnOpening() method of WebServiceHost can resolve the problem or not?
Upvotes: 0
Views: 1294
Reputation: 335
Easiest way is to configure it in web.config where you can change it later if needed. First create binding configuration as mentioned below in your web.config or 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>
Upvotes: 1
Reputation: 28338
MaxReceivedMessageSize
is a property of the binding element; if you need to change it from the defaults you have two options:
binding
element.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. 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:
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. 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. But I'm not really sure why you would go to all that trouble...
Upvotes: 1