It sounds like you need a semaphore with several machines, you can implement it with a distributed caching solution like memcached. Alternatively, you can use another WCF service on the same machine, which manages the semaphore for your load-balanced services.
Thus, a new service might look something like this:
[ServiceContract] public interface ISemaphorService { [OperationContract] void Acquire(); [OperationContract] void Release(); } [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class SemaphoreService { private readonly static Semaphore Pool = new Semaphore(5, 5); public void Acquire() { Pool.WaitOne(); } public void Release() { Pool.Release(); } }
In a real-world application, you might want the number of semaphores to be configured in a config or something else, and put in a few timeouts and enable a mechanism to ensure timely release of semaphores and / or when a client fails:
theburningmonk
source share