0
votes

We have set our service behaviour to [ServiceBehavior(Namespace = "abc", InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = false)]

as you can see we have set Concurrency Mode as Single but still we are able to see multiple ThreadID's in WCF Trace Log.

Need Help in making WCF calls Thread Safe so that each message is processed in sequenced.

Thanks, Srujal

1

1 Answers

0
votes

ConcurrencyMode controls threading per InstanceContext. Since you use InstanceContextMode = InstanceContextMode.PerSession you still allow to exist several service instances at the same time, one per session.

If you instead set InstanceContextMode = InstanceContextMode.Single you create a singleton service, i.e. only one single instance of your service. In combination with ConcurrencyMode = ConcurrencyMode.Single this will achieve the desired behavior:

The service instance is single-threaded and does not accept reentrant calls. If the InstanceContextMode property is Single, and additional messages arrive while the instance services a call, these messages must wait until the service is available or until the messages time out. (MSDN documentation ConcurrencyMode)

You can read more on Sessions, Instancing, and Concurrency on MSDN.