title: Best way to call many web services?
body: <p>I have 30 sub companies and every one has implemented their web service (with different technologies).</p>
  
  <p>I need to implement a web service to aggregate them, for example, all the sub company web services have a web method with name <code>GetUserPoint(int nationalCode)</code> and I need to implement my web service that will call all of them and collect all of the responses (for example sum of points).</p>
  
  <p>This is my base class:</p>
  
  <pre><code>public abstract class BaseClass
  { // all same attributes and methods
    public long GetPoint(int nationalCode);
  }
  </code></pre>
  
  <p>For each of sub companies web services, I implement a class that inherits this base class and define its own <code>GetPoint</code> method.</p>
  
  <pre><code>public class Company1
  {
    //implement own GetPoint method (call a web service).
  }
  </code></pre>
  
  <p>to</p>
  
  <pre><code>public class CompanyN
  {
    //implement own GetPoint method (call a web service).
  }
  </code></pre>
  
  <p>so, this is my web method:</p>
  
  <pre><code>        [WebMethod]
          public long MyCollector(string nationalCode)
          {
  
             BaseClass[] Clients = new BaseClass[]  { new Company1(),//... ,new Company1()}
  
             long Result = 0;
             foreach (var item in Clients)
             {
                  long ResultTemp = item.GetPoint(nationalCode);
                  Result += ResultTemp;
             }
         return Result;
         }
  </code></pre>
  
  <p>OK, it works but it's so slow, because every sub companys web service is hosted on different servers (on the internet).</p>
  
  <p>I can use parallel programing like this:(is this called parallel programing!?)</p>
  
  <pre><code>    foreach (var item in Clients)
      {
                      Tasks.Add(Task.Run(() =&gt;
                          {
                          Result.AddRange(item.GetPoint(MasterLogId, mobileNumber));                  
                      }
        }
  </code></pre>
  
  <p>I think parallel programing (and threading) isn't good for this solution, because my solution is IO bound (not CPU intensive)! </p>
  
  <p>Call every external web service is so slow, am i right? Many thread that are pending to get response!</p>
  
  <p>I think async programming is the best way but I am new to async programming and parallel programing.</p>
  
  <p>What is the best way? (parallel.foreach - async TAP - async APM - async EAP -threading)</p>
  
  <p>Please write for me an example.</p>