Introduction
Concurrency is the control of multiple threads active in an InstanceContext at any given time. This is controlled using the System.ServiceModel.ServiceBehaviorAttribute. ConcurrencyMode is the ConcurrencyMode enumeration.
WCF concurrency will help us to configure how WCF service instances can serve multiple requests at the same time.
There are three basic types of concurrency supported by WCF 4.0:
- Single Concurrency Mode
- Multiple Concurrency Mode
- Reentrant Concurrency Mode
Single Concurrency Mode
- [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
- public class Service1 : IService1
- {
- public string GetData(int value)
- {
- return string.Format("You entered: {0}", value);
- }
- }
Every incoming request must try to acquire the sync lock; if no lock is found then it allows access to the service and this request makes a sync lock. When finished operations, WCF will unlock the sync lock and allow other requests to come in.
Multiple Concurrency Mode
- [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
- public class Service1 : IService1
- {
- readonly object ThisLock = new object();
- public string GetData(int value)
- {
- string myRetString = string.Empty;
- lock (this.ThisLock)
- {
- myRetString = string.Format("You entered: {0}", value);
- }
- return myRetString;
- }
- }
With Concurrency Mode Multiple, threads can call an operation at any time. It is our responsibility to guard our state with locks.
Reentrant Concurrency Mode
The Reentrant concurrency mode is nothing but a modified version of the single concurrency mode. Similar to single concurrency, reentrant concurrency is associated with a service instance and also sync lock. So that a concurrent call on the same instance is never called. In other words multiple calls on the same instance is not allowed.
- [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
- public class Service3 : IService1
- {
- public string GetData(int value)
- {
- return string.Format("You entered: {0}", value); ;
- }
- }
However, if the reentrant service call to another service or a callback, and that call chain (or causality) somehow wind its way back to the service instance.
The only case where a service configured with the Single Concurrency Mode can call back to its clients is when the callback contract operation is configured as one-way because there will not be a reply message to contend for the lock.
Reference

AKHIL LAL C VPosted Jun 30, 2020, 5:59 AM
Very good article. Is there a way that I can use this concurrency mode in a .net standard client.?