简体   繁体   English

.NET WSE客户端存根是否是线程安全的?

[英]Are .NET WSE client stubs thread-safe?

Are client stubs generated from WSDL by .NET WSE thread-safe? 客户端存根是否由.NET WSE线程安全的WSDL生成?

Of course, "thread-safe" isn't necessary a rigorously defined term, so I'm at least interested in the following: 当然,“线程安全”不是一个严格定义的术语,所以我至少对以下内容感兴趣:

Are different instances of the same stub class accessible concurrently by different threads, with the same effective behavior as single-threaded execution? 不同线程可以同时访问同一存根类的不同实例,具有与单线程执行相同的有效行为吗?

Is a single instance of the same stub class accessible concurrently by different threads, with the same effective behavior as the same calls interleaved in some arbitrary way in single-threaded execution? 同一个存根类的单个实例是否可以由不同的线程并发访问,并且在单线程执行中以相同的方式交错相同的有效行为?

You may also wish to use the terminology described here (and originating here ) to discuss this more precisely. 您可能还希望使用此处描述的术语(并在此处起源)来更精确地讨论这一术语。

Well, for the short answer of is it thread safe, is yes. 好吧,对于简短的回答是线程安全,是的。 The reason is that the server side of the service will have more to say then the client connection as to threading capabilities. 原因是服务的服务器端将有更多关于线程功能的客户端连接。 The client is just a proxy that lays out the request in a fashion that the server can understand. 客户端只是一个代理,以服务器可以理解的方式布局请求。 It knows nothing. 它什么都不知道。 It is a basic class, no outside access other than the connection to a server. 它是一个基本类,除了与服务器的连接之外没有外部访问。 So as long as the server allows multiple connections you would be fine. 因此,只要服务器允许多个连接,您就可以了。 Thus no resource contention (Except for the server being able to handle all your requests). 因此没有资源争用(除了服务器能够处理您的所有请求)。

On the client side you can have multiple threads use the same class but different instances. 在客户端,您可以让多个线程使用相同的类但不同的实例。 This would probably be the preferred scenario so that each transaction can be atomic. 这可能是首选方案,因此每个事务都可以是原子事务。 Whereas the shared instance you would have to handle your own thread locking around the access of the class itself otherwise you may run into a race condition on the resource internal to your code. 对于共享实例,您必须处理自己的线程锁定类本身的访问,否则您可能会遇到代码内部资源的竞争条件。

There is also the ability to have a asynchronous call. 还可以进行异步调用。 The stubs generated by wsdl tool will create the begin, end invoke methods so that you can provide a callback method to effectively allow you to submit your request and continue your code without waiting for a reply. wsdl工具生成的存根将创建开始,结束调用方法,以便您可以提供回调方法,以有效地允许您提交请求并继续您的代码,而无需等待回复。 This would probably be the best for your second scenario with the single instance. 对于单个实例的第二个场景,这可能是最好的。

However it also depends on how the server component is coded. 但是,它还取决于服务器组件的编码方式。 If it's a webservice you should be able to submit multiple requests simultaneously. 如果它是一个Web服务,您应该能够同时提交多个请求。 However if it's a socket based service you may need to do some additional coding on your end in order to handle multiple incoming connections or even to create sockets for example. 但是,如果它是基于套接字的服务,您可能需要在您的端部进行一些额外的编码,以便处理多个传入连接,甚至创建套接字。

So in short yes the different instances behave the same as single threaded execution within the limits of the server side being able to handle multiple concurrent connections. 因此,简而言之,不同的实例与服务器端限制内的单线程执行行为相同,能够处理多个并发连接。

As for the single instance if you use a callback process, which is provided you may be able to get what you are after without too much headache. 至于单个实例,如果你使用回调过程,这可以让你得到你想要的东西而不用太多头痛。 However it is also restricted to the limits of the server side code. 但是,它也受限于服务器端代码的限制。

The reason I state the server limits is that there are companies that will build webservices that restrict the number of connections coming from outbound hosts so your throughput is limited by this. 我说明服务器限制的原因是,有些公司将构建限制来自出站主机的连接数的Web服务,因此您的吞吐量受此限制。 Thus the number of effective threads you could use would be reduced or made obsolete. 因此,您可以使用的有效线程数将减少或过时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM