WCF 10 connection limitation

Posted: 15th February 2010 in AJAX, WCF

Recently, I had a problem with an AJAX enabled application which was calling a WCF service. As can be seen below, in my calls to the Service, I used the “using statement” to allow the connection to the service to be closed after use. 

Code Snippet
  1. /// <summary>
  2.         /// Gets the towns.
  3.         /// </summary>
  4.         /// <returns>The list from the cache if it exists; or from the database</returns>
  5.         public List<TownDto> GetTowns()
  6.         {
  7.             if (!this.cacheManager.Contains("towns"))
  8.             {
  9.                 using (var svc = new NetworkServiceClient())
  10.                 {
  11.                     var towns = svc.GetAllTowns();
  12.                     this.cacheManager.Add(
  13.                         "towns",
  14.                         towns,
  15.                         CacheItemPriority.Normal,
  16.                         null,
  17.                         new SlidingTime(TimeSpan.FromMinutes(Constants.CacheTimeout)));
  18.                 }
  19.             }
  21.             return (List<TownDto>)this.cacheManager.GetData("towns");
  22.         }

However, as i played with the application it became apparent that the more calls its made the slower the application became.   Eventually, after wading threw all the application tiers I found the culprit was: by default WCF only allows 10 connections, which meant my connections weren’t being closed by the using statement.

The code has now been refactored to close the service client explicitly. It now works!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s