I am developing a web application with several WCF service links. Currently, every time we need to call the service, we do the following (as an example):
Service.ServiceClient ServiceClient = new Service.ServiceClient(); ServiceClient.SomeMethod();
Would it be better to have a static class with static references to each Service and call this class instead, thereby avoiding creating a new instance of the ServiceClient object every time we want to call it?
For instance:
public static class Services { private static Service.ServiceClient _ServiceClient = new Service.ServiceClient(); public Service.ServiceClient ServiceClient { get { return _ServiceClient; } } }
And, if you do so, will there be a line
private static Service.ServiceClient _ServiceClient = new Service.ServiceClient();
causes the creation of a new object every time we try to call this object, or will it be the same instance of this object every time we call it?
source share