c# - Managing and Restricting the Number of API Sessions -



c# - Managing and Restricting the Number of API Sessions -

i'm working wsdl api has limit of 100 sessions @ time. i'm using c#, means in application can ever have in existence 100 instances of wssession class, otherwise api reject calls.

what best way approach this? i'm working in big application nail 100 session limit. don't want throw error when session limit hit, instead i'd rather block until session available.

you can route remote calls through single service maintain counter of how many operations taking place @ time when phone call happens.

you can utilize semaphore command concurrency on given block.

assuming have proxy service created external webservice create service handle calls. i´m assuming using inversion of control, need sure there is single instance of service handling all calls.

there alternatives this;

moving semaphore out , making singleton or giving semaphore name.

service:

public class pooledservice { private readonly semaphore _semaphore; private readonly webservice _service; public pooledservice(webservice service, int max) { _semaphore = new semaphore(max, max); _service = service; } public r execute<r>(func<webservice, r> expression) { //will block if concurrency @ maximum, waiting 5 seconds //if want wait forever, phone call _semaphore.waitone(); if (!_semaphore.waitone(5000)) throw new exception("timed out"); seek { homecoming expression(_service); } { _semaphore.release(); } } public void execute(action<webservice> expression) { //will block if concurrency @ maximum, waiting 5 seconds //if want wait forever, phone call _semaphore.waitone(); if (!_semaphore.waitone(5000)) throw new exception("timed out"); seek { expression(_service); } { _semaphore.release(); } } }

you can utilize in way;

var service = new pooledservice(new webservice(), 100); //maximum of 100 concurrent calls var response = service.execute(s => s.someremotecall(...));

c# session design-patterns

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -