简体   繁体   English

创建异步-单调WCF服务

[英]Create a asynchronous - singletone WCF service

What is the best way to create a WCF service that will work for a number of clients but will provide equivalent information stored on the Service? 创建可用于许多客户端但将提供存储在该服务上的等效信息的WCF service最佳方法是什么?

I tried the following way: 我尝试了以下方法:

[ServiceBehavior (ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]

But because service it singletone it works very slow (probably it synchronous) when there are more than three clients. 但是,由于服务它是单调的,所以当有三个以上的客户端时,它的工作速度非常慢(可能是同步的)。

But I need that service will be singletone, because I have an object that suppose to gave the same information to all clients ( or there is another way to do this? ) 但是我需要该服务是单调的,因为我有一个对象想向所有客户端提供相同的信息( 或者有另一种方法可以做到这一点?

I would love to have other offers. 我希望有其他优惠。

You may want to lock the use of the object itself, or the critical section of the code. 您可能需要锁定对象本身或代码关键部分的使用。 There is no need to make the entire service singleton. 无需使整个服务单例。 However, without seeing the code it is hard to know if this will help. 但是,没有看到代码,很难知道这是否会有所帮助。 (Because if the long calculations are inside the critical section locking will not be helpful). (因为如果较长的计算在关键部分锁定之内将无济于事)。

EDIT: 编辑:

Just to clarify my answer, your problem has nothing to do with WCF. 只是为了澄清我的答案,您的问题与WCF无关。 You are really asking if you should pay the costs in complexity of the code in order to get better performance, or stick with a single thread handeling of this section of the code. 您实际上是在问是否应该为提高性能而付出代码复杂性的代价,还是坚持对代码这一部分进行单线程处理。 You would face the exact same issue if the call to the service was made from the same process (by different threads) and not from WCF client. 如果对服务的调用是从同一进程(通过不同的线程)而不是从WCF客户端进行的,则您将面临完全相同的问题。 So I suggest you read more about multi-threading and conecurrent collections before making up your mind. 因此,我建议您在下定决心之前先阅读有关多线程和并发集合的更多信息。

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

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