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