Error 

.Net Error: Maximum message size quota for incoming messages (65536) has been exceeded."an underlying connection was closed"


Solution

The message response was larger than the maxReceivedMessageSize set in your app.config


You need to modify your app.config file or programmatically set size in the bindings:


<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://pcmiler.alk.com/APIs/SOAP/v1.0/Service.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
                contract="IService" name="BasicHttpBinding_IService" />
        </client>
    </system.serviceModel>
</configuration>



Change this line from:  maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"


To:     maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"


You can also do it programmatically by setting the binding:



PCMService.ServiceClient service = new PCMService.ServiceClient();

service.Endpoint.Address = new EndpointAddress("http://pcmiler.alk.com/APIs/SOAP/V1.0/Service.svc");

PCMService.ServiceClient service = new PCMService.ServiceClient();


To dynamically create the binding information:


BasicHttpBinding binding = new BasicHttpBinding() {

MaxBufferSize = 2147483647,

MaxReceivedMessageSize = 2147483647

};

EndpointAddress endpoint = new EndpointAddress("http://pcmiler.alk.com/APIs/SOAP/v1.0/Service.svc");

PCMService.ServiceClient service = new PCMService.ServiceClient(binding, endpoint);