0

I currently have the following code:

    public static ICmsDataServiceWcf Data
    {
        get
        {
            if (HttpContext.Current != null && HttpContext.Current.Session != null && HttpContext.Current.Session["DataSevice"] == null)
            {
                HttpContext.Current.Session.Add("DataService", GetDataService());
            }

            if (HttpContext.Current != null && HttpContext.Current.Session != null && HttpContext.Current.Session["DataSevice"] != null)
            {
                return (ICmsDataServiceWcf)HttpContext.Current.Session["DataService"];
            }
            return GetDataService();
        }
    }

The purpose of this is to minimize the overhead involved in creating/destroying WCF clients. It appears to work quite well. One issue that I am having though is that quite a few requests come from Tasks in the background. These obviously don't have a context and therefor fall through to the return GetDataService() line.

What I'm thinking of doing is creating a static instance of the WCF client and returning that. One thing that concerns me about this approach though is that lots of tasks would be making lots of requests through a single instance. Would this end up being a bottlneck? If so then might it be a better idea to create a pool of say 10 WCF clients to spread the load out?

Thanks,

Joe

JoeS
  • 1,405
  • 17
  • 30
  • static proxy are not recommended, as the state of proxy from one bad request will kill other modules. look at the following question http://stackoverflow.com/questions/1681787/wcf-client-proxy-initialization – Dhawalk Mar 28 '13 at 12:40
  • You are optimizing something that is already fast and potentially introducing hard to find bugs. Unless you have performance measurements that show client creation to be an issue: don't do this. Create a new client instance for each thread and then close the instance when the work is done. – ErnieL Mar 28 '13 at 17:49

0 Answers0