Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASMX Web Service Method Singleton

Not sure if this is the right terminology, let me explain what I want.

I have a web service that's available on the network - the web service has 1 web method.

What I want is... if the web service is running and performing tasks and another call is made to this web service, I want the 2nd call to fail or pend for a certain period of time then fail. Because only 1 instance of this web service should be called at once.

I was thinking of writing a value to the application object (like in asp.net) but then I have to be very careful to make sure that this value gets updated, in case of any errors, it might not... so this is dangerous, and would leave the web service in a state where no one can get to it.

Is there not a more dynamic way to determine if the web service is getting called or not?

like image 997
JL. Avatar asked Dec 31 '25 20:12

JL.


2 Answers

You cannot do this with legacy ASMX web services. They have no support for different instance schemes.

I believe you can do this with WCF, as you can configure the service to have only a single instance.

like image 54
John Saunders Avatar answered Jan 02 '26 10:01

John Saunders


If you are using WCF, this is simple. Use the service throttling settings to specify that you want MaxConcurrentCalls = 1 and MaxInstances = 1. You'll also want to set the ConcurrencyMode to Single for your ServiceBehavior.

like image 41
bobbymcr Avatar answered Jan 02 '26 10:01

bobbymcr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!