title: Over 64 Client requests from WCF client rather than default 2?
body: <p>I have a WCF Web service client program that will send over 200 concurrent requests through either WCF client proxy async calls generated by SvcUtil.exe to the service. I had presumed that CLR will honer the maxconnection=2 in the client config.</p>
  
  <pre><code>  &lt;system.net&gt;
  &lt;defaultProxy enabled="true"&gt;
    &lt;proxy bypassonlocal="False" usesystemdefault="True" /&gt;
    &lt;bypasslist /&gt;
    &lt;module /&gt;
  &lt;/defaultProxy&gt;
  &lt;connectionManagement&gt;
    &lt;add address="*" maxconnection="2" /&gt;
  &lt;/connectionManagement&gt;
  </code></pre>
  
  <p></p>
  
  <p>I know the default value of maxconnection is 2 anyway, and my codes do NOT have System.Net.ServicePointManager.DefaultConnectionLimit defined. However, when I run Fiddler 2 to monitor the outbound requests, my program always sends 64 requests within 0.5 second concurrently, ignoring maxconnection.</p>
  
  <p>Here's the codes:</p>
  
  <pre><code>    namespace DemoClient
  {
      class Program
      {
          const string realWorldEndpoint = "DefaultBinding_RealWorld";
  
          static void Main(string[] args)
          {
              var list = new int[100];
              for (int i=0;i&lt;100;i++)
              {
                  list[i] = i;
              }
  
  
              var tasks  = list.Select(d =&gt;
              {
                  return GetHardData(d);
              });
  
              Task.WaitAll(tasks.ToArray());
  
              Console.WriteLine("All done.");
  
              Console.ReadLine();
          }
  
          static async Task&lt;string&gt; GetHardData(int d)
          {
              using(    RealWorldProxy client = new RealWorldProxy(realWorldEndpoint))
              {
                  client.ClientCredentials.UserName.UserName = "test";
                  client.ClientCredentials.UserName.Password = "tttttttt";
                  return await client.GetHardDataAsync(d);
  
              }
  
          }
      }
  }
  </code></pre>
  
  <p>and the implementation of GetHardData in the service side is:</p>
  
  <pre><code>        public string GetHardData(int value)
      {
          System.Threading.Thread.Sleep(40000);
          return string.Format("You entered: {0}", value);
      }
  </code></pre>
  
  <p>I understand my codes had spin off over 100 threads because of thread over-subscription intended, but I would expect them to be queued in the http connection pool which should allow only 2 outbound requests/connections by default.</p>
  
  <p>This behavior may cause client timeout if the Web service is not responding fast enough to finish 64 requests each in 60 seconds, since by default the Web service hosted in IIS will limit 2 concurrent calls from the same client, so the other 62 requests have to wait, thus some of them may timeout. </p>
  
  <p>Do I miss something?</p>
  
  <p>Technically I may construct a thread queue or a custom TaskScheduler to limit the number of concurrent calls to 2, however, I would like to rely to the default settings of thread pool and http / tcp pools to queue.</p>
  
  <p>Do I miss something? how to limit concurrent http requests of the WCF client according to maxconnection in config?</p>
  
  <p><img src="https://i.stack.imgur.com/Zptpx.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/guI6u.png" alt="enter image description here"></p>