I have a WCF Service that I want to process one request from all clients at a time. I want Client A’s request to be processed and Client B to wait until Client A is finished before the service even attempts to look at it. I thought the following code below accomplished this.
[ServiceContract]
public interface IRestServiceImpl
{...}
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
public class RestServiceImpl : IRestServiceImpl
{...}
How do I allow only a single client to be processed at one time and force others to wait in queue?
You need to control the number of instances of your service as well as the concurrency mode. By default, your service will be configured as
InstanceContextMode.PerSession. This means that all of Client A’s requests will be handled sequentially and so will Client B’s, but they will not be handled sequentially in regards to each other as they are not using the same instance of the service.Try modifying your
ServiceBehavioras follows:For more information on the topic, check out the MSDN documentation on Sessions, Instancing and Concurrency.