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();
3
  • 1
    I solved the problem by the step mentioned [here][1] [1]: stackoverflow.com/questions/7476853/…
    – Ram
    Commented Dec 28, 2011 at 13:28
  • 1
    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);
    – Rajesh
    Commented Jul 5, 2013 at 16:21
  • Does this answer your question? The maximum message size quota for incoming messages (65536) has been exceeded
    – KyleMit
    Commented Nov 5, 2019 at 17:25

3 Answers 3

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.

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?
    – rockin'
    Commented Dec 5, 2011 at 8:06
  • 1
    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.
    – Tim
    Commented Dec 5, 2011 at 8:15
  • is there any kind of example of server side binding and/or endpoint configuration? I'm already stuck at that point.
    – rockin'
    Commented Dec 5, 2011 at 8:33
  • @rockin' - Post your service's config file, please.
    – Tim
    Commented Dec 5, 2011 at 15:32
  • @rockin' - 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.
    – Tim
    Commented Dec 6, 2011 at 0:34
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>
1
  • 4
    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. Commented Aug 6, 2013 at 22:50
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.

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):
    – mihai71
    Commented May 17, 2017 at 10:23
  • ... 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.
    – mihai71
    Commented May 17, 2017 at 10:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.