The max message size quota for incoming messages (65536) ....To increase the quota, use the MaxReceivedMessageSize property
Asked Answered
R

3

25

I got this crazy problem I'm trying to deal with. I know that when we're getting huge amount of data we must increase the quota on client .config file, but what am I supposed to do if my client is sending huge data "to" the WCF server?

It works perfectly normal when I'm sending small sized input parameter. Unfortunately, it breaks down when the input grows bigger.

Debugger it says:

Bad Request, 400;

on trace file it is:

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.

Is there some way to increase this quota of incomming data on the server side? if so, how?

Here's my sample config related parts:

<bindings>
  <basicHttpBinding>
    <binding name="MyBasicHttpBinding"
        closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
        sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
        hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647"
        maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647"
          maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"  />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>

  </basicHttpBinding>
</bindings>

 <services>
  <service name="MyWcfService">
    <endpoint address="http://myservice..."
      binding="basicHttpBinding" bindingConfiguration="MyBasicHttpBinding"
      name="MyBasicHttpBinding" contract="IMyContract" />
  </service>
</services> 

and here's my client-side code (I create it dynamically):

        var binding = new BasicHttpBinding();
        binding.MaxBufferPoolSize = 2147483647;
        binding.MaxBufferSize = 2147483647;
        binding.MaxReceivedMessageSize = 2147483647;
        binding.ReaderQuotas.MaxStringContentLength = 2147483647;
        binding.ReaderQuotas.MaxArrayLength = 2147483647;
        binding.ReaderQuotas.MaxDepth = 2147483647;
        binding.ReaderQuotas.MaxBytesPerRead = 2147483647;


        var address = new EndpointAddress("http://mylocalservice.."); 

        ChannelFactory<IMyContract> factory = new ChannelFactory<IMyContract>(binding, address);

        foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
        {
            DataContractSerializerOperationBehavior dataContractBehavior =
                        op.Behaviors.Find<DataContractSerializerOperationBehavior>()
                        as DataContractSerializerOperationBehavior;
            if (dataContractBehavior != null)
            {
                dataContractBehavior.MaxItemsInObjectGraph = 2147483646;
            }
        }
        public IMyContract MyClientObject = factory.CreateChannel();
Resurge answered 5/12, 2011 at 7:54 Comment(3)
I solved the problem by the step mentioned [here][1] [1]: #7477353Chiou
In your client side code you are setting the readerquotas via code so the below is the approach to set them : XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas(); myReaderQuotas.MaxStringContentLength = 2147483647; myReaderQuotas.MaxArrayLength = 2147483647; myReaderQuotas.MaxBytesPerRead = 2147483647; myReaderQuotas.MaxDepth = 64; myReaderQuotas.MaxNameTableCharCount = 2147483647; binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, myReaderQuotas, null);Bradybradycardia
Does this answer your question? The maximum message size quota for incoming messages (65536) has been exceededFormation
C
47

You can set the MaxReceivedMessageSize property on the service via the service's config file.

Setting the client's MaxReceivedMessageSize only affects messages received by the client; it has no effect on messages received by the service. Correspondingly, to allow the service to receive large messages, you need to set the service's config file.

Sample Service Config

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="MyBinding" maxReceivedMessageSize="2147483647" />
    </wsHttpBinding>
  </bindings>
  <services>
    <service name="MyService">
      <endpoint address="http://myservice" binding="wsHttpBinding"
                bindingConfiguration="MyBinding" contract="IMyServiceContract" />
    </service>
  </services>
</system.serviceModel>

The above is a very stripped down config file, but shows the relevant parts. The important part is that you define the binding and give it a name, and set any values explicitly that are different from the defaults, and use that name in the bindingConfiguration attribute on the endpoint element.

Castanon answered 5/12, 2011 at 8:3 Comment(7)
the thing is I don't see any binding configuration on server side. is there some default binding or something? how can I override it?Band
Yes, there is. If you don't have a specific binding section in your config file, and it's not referenced in the <endpoint> element via the bindingConfiguration attribute, the default values for the binding will be used (which is 65536 for MaxReceivedMessageSize property). So you'll need to add the appropriate <binding> section to the config.Castanon
is there any kind of example of server side binding and/or endpoint configuration? I'm already stuck at that point.Band
@Resurge - Post your service's config file, please.Castanon
@Resurge - the config file looks right. How are you creating the proxy on the client? Can you add that bit of code to your question? Depending on how you're creating it, that might be where the problem lies. I can probably tell for sure once I see the code.Castanon
How to do the setting at client's MaxReceivedMessageSize when the client is MS Excel?Condescendence
Hi Everyone, Is there any alternative ways to communicate large data b/w client and serverExtension
B
7

This issue can be resolved by adding the below additional binding node to the binding section of config file.

<basicHttpBinding>
  <binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
       maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
  </binding>
</basicHttpBinding>
Brainwashing answered 6/8, 2013 at 22:31 Comment(1)
Welcome to StackOverflow. The OP has a very similar code in their config. In which way is your answer better than what they had? You can improve your answer by explaining answer does that they didn't do before.Oops
A
7

My problem was with the wcf test client. For some reason, it wouldn't generate a client config with the increased maxReceivedMessageSize. My fix was to right click "Config file" -> "Edit with SvcConfigEditor" -> bindings -> maxReceivedMessageSize.

Alewife answered 24/10, 2014 at 0:37 Comment(2)
in most answers they show how to set these settings on the server. but if still error then, as you mentioned, we should also config these settings on the client. in my case , the app.config of the application that consumes the webservice first looked like this: <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_ICGSIncomingSOAPCalls" /> <binding name="BasicHttpBinding_MyICGSIncomingSOAPCalls" /> </basicHttpBinding> </bindings> I modified like this (see part 2):Sharpen
... part 2: <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_ICGSIncomingSOAPCalls" maxReceivedMessageSize="10485760" maxBufferPoolSize="10485760" maxBufferSize="10485760" /> <binding name="BasicHttpBinding_MyICGSIncomingSOAPCalls" maxReceivedMessageSize="10485760" maxBufferPoolSize="10485760" maxBufferSize="10485760" /> </basicHttpBinding> </bindings> and it worked ok.Sharpen

© 2022 - 2024 — McMap. All rights reserved.