Problems returning a large amount of data through WCF

Asked

Viewed 5,523 times

4

Good Afternoon,

I have a web service done in WCF, when I do a query in the bank and return a large amount of records it gives me the following error:

An unhandled Exception of type 'System.ServiceModel.Communicationexception' occurred in mscorlib.dll Additional information: The maximum size quota for incoming messages (65536) has been exceeded. To increase the quota, use the Maxreceivedmessagesize property in the appropriate association element.

someone can help me?

  • 1

    You must increase the property maxReceivedMessageSize in the binding of your customer. How is your customer defined? Using ChannelFactory directly, using a class generated by Add Service Reference, in some other way?

  • Carlos, is defined by the class generated by the Add Service Reference

  • I increased the property maxReceivedMessageSize, maxBufferSiz,maxBufferPoolSize and it worked, thank you !

1 answer

9


When you use the "Add Service Reference" to generate the client for the WCF service, this tool adds in your configuration file (app.config or web.config) the information necessary for the client to communicate with the server. One of them is the binding to be used.

You can change the configuration of binding to increase this share that the error message is saying is being exceeded. For example:

<bindings>
  <basicHttpBinding>
    <binding
        name="BasicHttpBinding_MyService"
        maxReceivedMessageSize="1000000" />
  </basicHttpBinding>
</bindings>

Another alternative is to do this in the code, before calling a client function for the first time, as in the example below.

        var c = new ServiceReference1.MyServiceClient();
        var binding = c.Endpoint.Binding;
        if (binding is BasicHttpBinding)
        {
            ((BasicHttpBinding)binding).MaxReceivedMessageSize = 1000000;
        }
        else if (binding is WSHttpBinding)
        {
            ((WSHttpBinding)binding).MaxReceivedMessageSize = 1000000;
        }
        else
        {
            // outros tipos
            var newBinding = new CustomBinding(binding);
            for (var i = 0; i < newBinding.Elements.Count; i++)
            {
                if (newBinding.Elements[i] is TransportBindingElement) {
                    ((TransportBindingElement)newBinding.Elements[i]).MaxReceivedMessageSize = 1000000;
                }
            }

            c.Endpoint.Binding = newBinding;
        }
  • Solved , Thanks carlosfigueira

Browser other questions tagged

You are not signed in. Login or sign up in order to post.