Service Message Size Limits

JustinCase

New member
Joined
Apr 19, 2019
Messages
2
Programming Experience
10+
I am struggling with the settings for message size in WCF services. I have a windows service that hosts a wcf service. It runs great and I use a WPF application to communicate with it.
At one point i start to receive an arror as follows, on a single service call (and not any others):
System.ServiceModel.CommunicationException
HResult=0x80131501
Message=An error occurred while receiving the HTTP response to http://localhost:8001/CAASService/service. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
Source=mscorlib
StackTrace:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

..................

Inner Exception 1:
WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Inner Exception 2:
IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

Inner Exception 3:
SocketException: An existing connection was forcibly closed by the remote host
The message could have been better, but i traced it to the size of the return message from the service. I can confirm this as I am debugging the service, and can see that the function completes successfully before the error occurs in the receiving application only. And if i remove a certain number of subitems from the return message (witch is a complex object), then everything works fine.

Now, there seems to be quite straight forward ways to increase message sizes, however all I have tried have had absolutely no effect. My App.Config (Client AND server) is now littered with settings that seem to have no impact.

Here is my server app.config:
XML:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <httpRuntime maxRequestLength="51200"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="CAASBinding" messageEncoding="Text" allowCookies="true" maxReceivedMessageSize="52428800" maxBufferSize="52428800" maxBufferPoolSize="52428800" transferMode="Streamed" closeTimeout="00:50:00" openTimeout="00:50:00" sendTimeout="00:50:00" receiveTimeout="00:50:00"  >
          <readerQuotas maxDepth="52428800" maxStringContentLength="52428800" maxArrayLength="52428800" maxBytesPerRead="52428800"
                        maxNameTableCharCount="52428800" />
         </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="CAASServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata httpGetEnabled="true" />
          <dataContractSerializer maxItemsInObjectGraph="52428800" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
          <behavior name="CAASEPBehavior">
            <dataContractSerializer maxItemsInObjectGraph="52428800" />
          </behavior>
        </endpointBehaviors>
      </behaviors>
    <services>
      <service name="CAASService.GameService" behaviorConfiguration="CAASServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8001/CAASService/service" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" behaviorConfiguration="CAASEPBehavior" contract="CAASService.IGame" bindingConfiguration="CAASBinding" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
</configuration>
And my client app.config:
XML:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
  <system.web>
    <httpRuntime maxRequestLength="51200"/>
  </system.web>
  <system.net>
    <defaultProxy>
      <proxy bypassonlocal="False" usesystemdefault="True" />
    </defaultProxy>
  </system.net>
    <system.serviceModel>
      <behaviors>
        <endpointBehaviors>
          <behavior name="CAASEPBehavior">
            <dataContractSerializer maxItemsInObjectGraph="52428800" />
          </behavior>
        </endpointBehaviors>
      </behaviors>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IGame" closeTimeout="00:50:00" messageEncoding="Text"
                    openTimeout="00:50:00" receiveTimeout="00:50:00" sendTimeout="00:50:00"
                    allowCookies="true" maxBufferPoolSize="52428800" maxBufferSize="52428800" maxReceivedMessageSize="52428800" transferMode="Streamed" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8001/CAASService/service"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGame"
                contract="CAASService.IGame" name="BasicHttpBinding_IGame" behaviorConfiguration="CAASEPBehavior" />
        </client>
    </system.serviceModel>
</configuration>
I have attempted several combinations here (also tried using wsHttpBinding), but nothing has the slightest effect and I am growing impatient. Does anyone have a tip for me?
 
Last edited by a moderator:

JustinCase

New member
Joined
Apr 19, 2019
Messages
2
Programming Experience
10+
Ok so I figured this out, and it had nothing to do with the message size. The problem was errors in certain rows of the underlying data, so an Enum value could not be resolved.
Achieved this by using the following:

XML:
  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="sdt"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "SdrConfigExample.e2e" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
The more detailed error now appeared in the log file.
 
Last edited by a moderator:
Top Bottom