title: CommunicationException when Converting WCF Service from WsHttpBinding to NetTcpBinding
body: <p>I have a self hosted .Net 4.0 WCF service that I'm trying to convert from WsHttpBinding to NetTcpBinding for performance reasons.  The service works just fine with the WsHttpBinding.</p>
  
  <p>Strangely enough, The service seems to work after switching to NetTcpBinding.  (The service posts messages to a enterprise messaging system, and the message is posted and the client receives no error) however the following error is written to the server log:</p>
  
  <pre><code>Error: Service: MessageSenderService, Details: System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused
  by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue.
  Local socket timeout was '10675199.02:48:05.4775807'. ---&gt; System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
     at System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted()
     at System.ServiceModel.Channels.SocketConnection.BeginReadCore(Int32 offset,Int32 size, TimeSpan timeout, WaitCallback callback, Object state)
     --- End of inner exception stack trace ---
     at System.ServiceModel.Channels.SocketConnection.BeginReadCore(Int32 offset,Int32 size, TimeSpan timeout, WaitCallback callback, Object state)
     at System.ServiceModel.Channels.TracingConnection.BeginRead(Int32 offset, Int32 size, TimeSpan timeout, WaitCallback callback, Object state)
     at System.ServiceModel.Channels.SessionConnectionReader.BeginReceive(TimeSpan timeout, WaitCallback callback, Object state)
     at System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult.PerformOperation(TimeSpan timeout)
     at System.ServiceModel.Channels.SynchronizedMessageSource.SynchronizedAsyncResult`1..ctor(SynchronizedMessageSource syncSource, TimeSpan timeout, AsyncCallback callback, Object state)
     at System.ServiceModel.Channels.TransportDuplexSessionChannel.BeginReceive(TimeSpan timeout, AsyncCallback callback, Object state)
     at System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceiveAsyncResult..ctor(TransportDuplexSessionChannel channel, TimeSpan timeout, AsyncCallback callback, Object state)
     at System.ServiceModel.Channels.TransportDuplexSessionChannel.BeginTryReceive(TimeSpan timeout, AsyncCallback callback, Object state)
     at System.ServiceModel.Dispatcher.ErrorHandlingReceiver.BeginTryReceive(TimeSpan timeout, AsyncCallback callback, Object state)
  </code></pre>
  
  <p>Again, no error occurs on the server log when using the WsHttpBinding.</p>
  
  <p>Server Config:</p>
  
  <pre><code>      &lt;service behaviorConfiguration="debugEnabled" name="My.Service"&gt;
          &lt;endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBindingConfig"
            contract="My.Service.Contract" /&gt;
          &lt;endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" /&gt;
        &lt;/service&gt;
  ....
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="debugEnabled"&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
            &lt;serviceThrottling maxConcurrentSessions="200" maxConcurrentCalls="500" maxConcurrentInstances="200"/&gt;
            &lt;serviceMetadata httpGetEnabled="true" /&gt;
            &lt;dataContractSerializer maxItemsInObjectGraph="2147483647"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
  ....
      &lt;bindings&gt;
        &lt;netTcpBinding&gt;
          &lt;binding name="netTcpBindingConfig" maxReceivedMessageSize="5242880" closeTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00" openTimeout="00:01:00"&gt;
            &lt;readerQuotas maxArrayLength="5242880" /&gt;
            &lt;security mode="None" /&gt;
          &lt;/binding&gt;
        &lt;/netTcpBinding&gt;
      &lt;/bindings&gt;
  </code></pre>
  
  <p>We build the client binding in code, not config.  That looks like this:</p>
  
  <pre><code>return new NetTcpBinding(SecurityMode.None, reliableSessionEnabled)
  {
      MaxBufferPoolSize = Int32.MaxValue,
      MaxReceivedMessageSize = Int32.MaxValue,
      ReaderQuotas = new XmlDictionaryReaderQuotas
      {
          MaxArrayLength = Int32.MaxValue,
          MaxDepth = Int32.MaxValue,
          MaxStringContentLength = Int32.MaxValue
      },
      ReceiveTimeout = TimeSpan.FromMinutes(1.0),
      CloseTimeout = TimeSpan.FromMinutes(1.0),
      OpenTimeout = TimeSpan.FromMinutes(1.0),
      SendTimeout = TimeSpan.FromMinutes(1.0)
  };
  </code></pre>
  
  <p>Any ideas out there?</p>
  
  <p>EDIT:  I would like to add that I see the error on every call to the service, not only under load.  The request and response messages are very small so it likely not related to message size.  The error is written almost instantaneously, so it it not a timeout problem.</p>