Traditionally in our web pages we have instantiated a service client in each page and then called the WCF methods from that instance, adding some caching code to check if the data exists and if not, make the WCF call and cache the data for the next time.
As our site grows we find we're repeating this same pattern and are looking to move it all to a single class.
Can we make that class static, with a single static instance of the WCF client, and static methods, safely?
// assume WcfDataService has a GetFoo(int i) method
public static class WcfMethods
public static WcfDataService client = new WcfDataService("connectionType");
public static DataSet GetFoo(int i)
if (Cache["foo" + i] == null)
Cache.Insert("foo" + i, client.GetFoo(i));
return Cache["foo" + i] as DataSet;
Then in our pages we can just call WcfMethods.GetFoo(x) directly. Figure we have 100 users visiting our various pages simultaneously. Will this cause contention issues? Like I mentioned, up till now we've not used static instances.
It's not caused any problems, but we're just looking to refactor. I realize we could also use the above pseudo-code pattern using an instance class and methods instead static ones.
I haven't dealt with threading or synchro
View Complete Post