Is there a way to configure a WCF Service to create a new Thread to handle any new incoming request?
Yes you can do that - it's called "per-call" handling of requests. The ServiceHost will create a new instance of your service class for each request coming in to handle that one request.
To do this, you need to set your Service class (the one implementing the service interface) to be "PerCall" - you do this by applying an attribute on your service class:
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
public class YourService : IYourService
{
...
}
Marc
Depends on what exactly you want, but the following service behaviour will solve it:
ServiceBehavior:
ConcurrencyMode=ConcurrencyMode.Multiple
InstanceContextMode=InstanceContextMode.Single
Your class will be a singleton, but all calls made to the methods will run in a separate thread. If you need any synchronization though you have to do it manually.
Also don't forget to look into throttling to be aware of potential performance issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With