0

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?

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.

4

1 回答 1

1

您可能希望锁定对象本身的使用,或代码的关键部分。无需将整个服务设为单例。但是,如果没有看到代码,很难知道这是否会有所帮助。(因为如果长计算在关键部分锁定将无济于事)。

编辑:

只是为了澄清我的回答,您的问题与 WCF 无关。你真的在问你是否应该为代码的复杂性付出代价以获得更好的性能,或者坚持对这部分代码进行单线程处理。如果对服务的调用是从同一个进程(通过不同的线程)而不是从 WCF 客户端进行的,您将面临完全相同的问题。所以我建议你在下定决心之前阅读更多关于多线程和锥电流集合的信息。

于 2013-08-27T11:26:01.953 回答