简体   繁体   中英

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?

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. 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. So I suggest you read more about multi-threading and conecurrent collections before making up your mind.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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