I\'m new to WCF services and wondered what the best way to tackle the following would be.
I have many clients (~200 - ~500) that are all making requests of my service fa
As Marcos already mentioned - WCF has a built-in service throttling capability, which you can tweak on the server. This prevents that your database server will be flooded with too many requests at once.
The defaults are:
See the MSDN docs on ServiceThrottlingBehavior for more details.
This means that a maximum of 16 calls are handled concurrently by WCF - that is, IF your WCF service class allows multiple callers at once!
Contrary to Marcos, I would not recommend making your WCF service class a singleton. The common best practice is to have a simple WCF service class, and use it in a per call fashion - e.g. each incoming request will get its own, totally separate, newly created instance of your WCF service class - up to a maximum as defined by the service throttling behavior and controlled by the WCF runtime.
If you make your WCF service class a singleton, you have to either set its ConcurrencyMode to Multiple - but then you need to use extreme caution not to let two simultaneous threads in your class change the same values from under one another; multi-threading safe programming is a major challenge! Or you don't set the concurrency mode to Multiple, but then your one and only WCF Service class instance can only handle requests in a serial fashion, one at a time - not very scalable!
Per-call and one service instance per request is definitely the much easier way to go. That with service throttling in place, and with ADO.NET connection pooling makes for a very powerful and well behaved environment!
Also see Dan Rigsby's excellent blog post on WCF service throttling for even more detail.