title: Multi-threaded async web service call in c# .net 3.5
body: <p>I have 2 ASP.net 3.5 asmx web services, <strong>ws2</strong> and <strong>ws3</strong>. They contain operations <strong>op21</strong> and <strong>op31</strong> respectively. op21 sleeps for <strong>2 seconds</strong> and op31 sleeps for <strong>3 seconds</strong>. I want to call both op21 and op31 from <strong>op11</strong> in a web service, <strong>ws1</strong>, asynchronously. Such that when I call <strong>op11</strong> from a client synchronously.,the time-taken will be <strong>3 seconds</strong> which is the total. I currently get <strong>5 seconds</strong> with this code:</p>
  
  <pre><code>WS2SoapClient ws2 = new WS2SoapClient();
  WS3SoapClient ws3 = new WS3SoapClient();
  
  //capture time
  DateTime now = DateTime.Now;            
  //make calls
  
  IAsyncResult result1 = ws3.BeginOP31(null,null);
  IAsyncResult result2 = ws2.BeginOP21(null,null);
  WaitHandle[] handles = { result1.AsyncWaitHandle, result2.AsyncWaitHandle };
  
  WaitHandle.WaitAll(handles);
  
  //calculate time difference
  TimeSpan ts = DateTime.Now.Subtract(now);
  return "Asynchronous Execution Time (h:m:s:ms): " + String.Format("{0}:{1}:{2}:{3}",
  ts.Hours,
  ts.Minutes,
  ts.Seconds,
  ts.Milliseconds);
  </code></pre>
  
  <p>The expected result is that the total time for both requests should be equal to the time it takes for the slower request to execute. </p>
  
  <p>Note that this works as expected when I debug it with Visual Studio, however when running this on IIS, the time is 5 seconds which seems to show the requests are not processed concurrently.</p>
  
  <p>My question is, is there a specific configuration with IIS and the ASMX web services that might need to be setup properly for this to work as expected?</p>