views:

117

answers:

3

Hi,

I created a Web Service proxy with the "add web reference" feature of VS 2008 (c#).

The generated class derives from SoapHttpClientProtocol

Can I store only one instance of my proxy in a singleton? Is it thread safe? Is there state between calls that would prevent me from doing this?

Thanks!

A: 

Per this link: http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soaphttpclientprotocol.aspx

at the bottom under 'thread safety' it says this type is thread safe. I do however not know that using it as a Singleton will be Thread safe.

Tony
A: 

MSDN makes no mention that it's thread safe:

Thread Safety

This type is thread safe.

The class is safe, no mention of the object.

But it is safe to say that that it's not thread safe - no object in the .NET library is thread safe.

(At least i've never seen one)

Ian Boyd
Usually for non-threadsafe types the wording would be "All class members are guaranteed to be thread-safe. All instance members are not guaranteed to be thread-safe." so I'd assume that "This type is thread-safe" implies both class and instance members.
Joey
ok I'm confused... maybe a better question would have been: "Is creating an instance of the web service proxy for each call to a web method a performance downer?" :P
Mike Gleason jr Couturier
i assume by "type" they mean just the type (it's type information), as opposed to static class members, or instance members, which are not thread-safe.
Ian Boyd
+1  A: 

No. It is not thread safe. the client must be in the Open state to enable calls. A simple scenario where one thread does client.Close() while another tries to call a method will fail.

AZ