title: WCF Service called from SharePoint workflows - Underlying connection was closed errors
body: <p>I have developed a WCF Web Service that is called from several SharePoint Online workflows. At certain points there could be around 4 users starting up to 10 workflows within a very short time frame: one workflow could possibly make as much as 3 requests to the web service. Needless to say, at certain points, the WCF Service becomes overloaded. When SharePoint workflows make HTTP web service calls and the service is unavailable, the workflow runs into an error and attempts to restart the workflow after a short period of time: which only contributes to making things worse.</p>
  
  <p>These are some of the exceptions logged today from the web service during an approximate 40 minute of "overloading":</p>
  
  <blockquote>
    <p>Unable to read data from the transport connection: An existing
    connection was forcibly closed by the remote host.</p>
    
    <p>The underlying connection was closed: An unexpected error occurred on
    a receive.</p>
    
    <p>The underlying connection was closed: A connection that was expected
    to be kept alive was closed by the server.</p>
  </blockquote>
  
  <p>I have tried to look into ways to avoid the WCF web service from malfunctioning when several requests are being made and besides the obvious actions of finding ways to decrease the amount of calls made to the web service (which is not always an option), I came into the terms: <strong>WCF Concurrency Modes</strong> and <strong>Throttling Limits</strong>. </p>
  
  <p>Given the scenario described above, could anyone guide me into the right direction as to which Concurrency Mode and Throttling limits would be most ideal? Presently, my WCF service has default configuration. </p>
  
  <p>Concurrency Modes can be:</p>
  
  <blockquote>
    <p><strong>Single</strong> or
    <strong>Multiple</strong> or
    <strong>Reentrant</strong></p>
  </blockquote>
  
  <p>Throttling Limit options are shown below:</p>
  
  <pre><code>&lt;serviceThrottling maxConcurrentCalls="Integer"  
  maxConcurrentInstances="Integer"  
  maxConcurrentSessions="Integer" /&gt;  
  </code></pre>
  
  <p>I am still quite new to this area of programming and am finding it a tad complicated, so any help would be greatly appreciated!</p>
  
  <p>Update: The SharePoint system is highly customised and it covers a Business process that is quite complicated. The Web Service methods are varied and it would take me a long time to explain what every method does but I will mention some examples. The web service is used for operations that either cannot be done (easily or at all) using out of the box SharePoint designer actions. For example: moving documents and copying metadata from one folder to another (in the same or different lists), syncing information between lists/libraries, calculating values based on metadata of several documents living within a given folder, scheduling data into an external database to be used with other components such as a console application running as a scheduled task, etc. </p>
  
  <p>The web service calls take an average of 2 minutes to execute and return a value. The fastest methods take around 30 seconds, and the slowest around 4 minutes. Both the slow and fast methods are frequently utilised.</p>