views:

16

answers:

1

I am using a Visual Studio generated proxy class for communicating with a SOAP web service. The generated class derives from System.Web.Services.Protocols.SoapHttpClientProtocol. I find the class is expensive to instantiate, so I am considering modifying my factory method to return a Singleton instance of the class. According to the documentation, the class is safe for multithreading.

Does anyone have experience with reusing instances of these classes? Are there any negatives to doing so (i.e. connections left open, etc.)?

.NET Framework Version: 2.0

A: 

There should be no reason that using these classes in a singleton pattern should cause a problem, however i am stuggling to unserstand what problem you are trying to solve. When you say these classes are expensive to instantiate what are you comparing them with? The cost of instantiating a proxy class should be neglible in comparison to the cost of making an http request to a web service. Could you explain the circumstances/post some code that demonstrates your performance bottle neck is being caused by instantiating the proxy classes.

Ben Robinson
It turns out the cost of instantiation was due to loading the web service URL from the generated settings in the application configuration file. This is a one time cost, so you are correct, there should not be a need for reusing the proxy instances.
Mario