WCF service that creates a new thread for each new request

Is there a way to configure the WCF service to create a new thread to handle any new incoming request?

+5
source share
3 answers

Yes, you can do this - it is called a "call" request processing. ServiceHost will create a new instance of your service class for each incoming request to process this single request.

To do this, you need to set the class of service (the one that implements the service interface) as "PerCall" - you do this by applying the attribute in your class of service:

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
public class YourService : IYourService
{
...
}

Mark

+6
source

, , :

ServiceBehavior:
ConcurrencyMode=ConcurrencyMode.Multiple
InstanceContextMode=InstanceContextMode.Single

, , , . - , .

, .

+3

, . ?

, .

" " , InstanceContextMode.PerCall marc_s.

If you need some state to be in the streaming local storage for your call, you can use ICallContextInitializer as the marshal state way to the stream that WCF chooses to call your method (and clears the state of the stream when the call ends).

But you do not have to worry about "which thread". WCF will handle this with a thread pool on your behalf.

0
source

All Articles