Is SoapHttpClientProtocol thread safe?

前端 未结 4 580
野趣味
野趣味 2020-12-19 01:15

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

The generated class derives from SoapHttpClientProtocol

Ca

相关标签:
4条回答
  • 2020-12-19 01:45

    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.

    0 讨论(0)
  • 2020-12-19 01:52

    MSDN says that SoapHttpClientProtocol is thread safe:

    Thread Safety

    This type is thread safe.

    For another class like System.Windows.Forms which isn't thread-safe, MSDN says,

    Thread Safety

    Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


    Here is a Microsoft/MSDN employee saying (though without guarantee) that it is thread-safe:

    Hi Max,

    For the webservice proxy, I think it should be thread-safe as the .NET generated proxy class is derived from the "SoapHttpClientProtocol" class which is marked as thread-safe in document:

    SoapHttpClientProtocol Class

    http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soaphttpclientprotocol(VS.71).aspx

    therefore, it should be safe to use it in multi-thread context as long as you haven't manually add any context-sensitive member in the derived proxy class. Do you think so?

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead

    This posting is provided "AS IS" with no warranties, and confers no rights.

    0 讨论(0)
  • 2020-12-19 01:55

    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)

    0 讨论(0)
  • 2020-12-19 02:03

    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.

    0 讨论(0)
提交回复
热议问题