title: Client-Side CommunicationException while Service works properly
body: <p>Currently i am facing a problem i do not understand. I have an wcf client that calls a wcf service through several threads at the same time (both on the same machine). Sometimes, i encounter the well-known System.ServiceModel.CommunicationException </p>
  
  <p><b>"An error occurred while receiving the HTTP response to xxx. 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." </b>, </p>
  
  <p>sometimes it works. It seems completely random if the service call succeeds. </p>
  
  <p>The request is very small, its just an (int, bool, enum) call. The request contains ca. 300-500 KB records from a MSSQL database.</p>
  
  <p>I searched on hundreds on websites for a solution, increased timeout values, buffer values, request and response size values on the client and service side. I added [DataContract] and [DataMember] attributes were they were missing. And still there is no change.</p>
  
  <p>I activated full tracing, just to see a very strange behaviour:</p>
  
  <p>The calls from the client stop locally with the given exception - but the server processes them and sends a response, that never reaches the client. Check the time at the given trace - the client aborts, the server continues.</p>
  
  <p>In the tracing, i see the heaviour like in this graph:</p>
  
  <p><img src="https://i.stack.imgur.com/HjxAA.png" alt="enter image description here"></p>
  
  <p>Please, can anyone help to stop this endless search?</p>
  
  <p><b>Update 1:</b></p>
  
  <p>I uploaded the <a href="http://pastebin.com/W7jV6YD2" rel="nofollow noreferrer">client</a> and <a href="http://pastebin.com/kASwDEmt" rel="nofollow noreferrer">server</a> config, maybe this helps.</p>
  
  <p><b>Update 2:</b></p>
  
  <p>We included the <a href="http://msdn.microsoft.com/en-us/library/fb6y0fyc%28v=vs.100%29.aspx" rel="nofollow noreferrer">config parameter</a> for the ConnectionLimit (connection=80), as suggested from Yahia. Currently, it seems that this solved the problem, but we still try to reproduce the error.</p>
  
  <p><b>Update 3:</b></p>
  
  <p>Damn. After three hours, I can see the same behaviour again... We had another suggestion: As you can see, we are using quartz.net in the client, starting with 20 threads. The jobs the quartz engine executes connect to our service. Now I try to imagine what happens if, say 7 threads try to connect the service at the same time.</p>
  
  <p><b>Update 4:</b></p>
  
  <p>We have setup the tcp parameters in the registry as well as in the config. After a restart, experienced no change at all :( </p>
  
  <p>These were the registry changes:</p>
  
  <p>HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters - TcpNumConnections=65534<br/>
  HKLM\System\CurrentControlSet\Services\Tcpip\Parameters - MaxUserPort=65534<br/>
  HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings - MaxConnectionsPer1_0Server=20<br/>
  HKLM\Software\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_MAXCONNECTIONSPERSERVER - iexplore.exe=20<br/>
  HKLM\Software\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_MAXCONNECTIONSPERSERVER - MyClientsExeName.exe=20<br/></p>
  
  <p><b>Update 5:</b></p>
  
  <p><img src="https://i.stack.imgur.com/7kmJ3.png" alt="Client Trace">
  <img src="https://i.stack.imgur.com/zbnPE.png" alt="Server Trace"></p>
  
  <p><b>Update 6:</b></p>
  
  <pre><code>[DataContract]
  public class Currency
  {
      [DataMember]
      public int Id { get; set; }
  
      [DataMember]
      public string Code { get; set; }
  
      [DataMember]
      public string Name { get; set; }
  
      [DataMember]
      public ForeignNoteDetails ForeignNoteDetails { get; set; }
  
      [DataMember]
      public CurrencyRates Rates { get; set; }
  
      [DataMember]
      public PreciousMetallDetails PreciousMetallDetails { get; set; }
  
      [DataMember]
      public CurrencyType Type { get; set; }
  }
  
  [DataContract]
  public class ForeignNoteDetails
  {
      [DataMember]
      public double CardholderBillingCurrencyCode { get; set; }
  
      [DataMember]
      public string Country { get; set; }
  
      [DataMember]
      public string CountryCode { get; set; }
  
      [DataMember]
      public int CurrencyUnit { get; set; }
  
      [DataMember]
      public List&lt;string&gt; Notes { get; set; }
  }
  
  [DataContract]
  public class CurrencyRates
  {
      [DataMember]
      public ExchangeRate PurchaseRate { get; set; }
  
      [DataMember]
      public ExchangeRate SellRate { get; set; }
  }
  
  [DataContract]
  public class PreciousMetallDetails
  {
      [DataMember]
      public string PreciousMetalType { get; set; }
  
      [DataMember]
      public double Fineness { get; set; }
  }
  </code></pre>
  
  <p>Call to service:</p>
  
  <pre><code>        protected IEnumerable&lt;Currency&gt; GetCurrencyLevel(int id, bool netRate = true, RatesCalculationSource ratesSource = RatesCalculationSource.ReutersRates)
      {
          return this.calculationClient.GetCurrencyLevel(new RatesCalculationSetting() { CalculationLevelId = id, CalculateGrossRates = !netRate, Soruce = ratesSource });
      }
  </code></pre>
  
  <p>Client creation:</p>
  
  <pre><code>protected ICalculationServiceClientService calculationClient = IoC.DependencyManager.Resolve&lt;ICalculationServiceClientService&gt;();
  </code></pre>
  
  <p>Another call to the service (working):</p>
  
  <pre><code>this.calculationClient.DistributeTradingOfficeRatesLevels(branchOfficeLevelId, tradingLevelId);
  </code></pre>
  
  <p>Where this is defined as </p>
  
  <pre><code>void DistributeTradingOfficeRatesLevels(int branchOfficeRatesLevelId, int tradingOfficeRatesLevelId)
  </code></pre>
  
  <p><b>Update 7:</b></p>
  
  <p><img src="https://i.stack.imgur.com/cYwr3.png" alt="Exception details"></p>