How is a web service request handled in ASP.Net

When a client makes a web service request, how does asp.net assign an instance of the service class to handle that request?

Is a new instance of the service class created per request or is there pooling happening or is there a singleton instance used to handle all requests?

Answers


For classic ASMX services you definitely get a new instance with each request, just like an ASPX request. For a WCF service (.SVC) you do have more options, such as running as a singleton.

If you are interested in doing work with a singleton and pooling you can use the ASMX service simply as the lightweight proxy to pass the parameters back and forth. Your implementation of the service could be a singleton that lives with the App Pool for your web site. You will need to account for the App Pool being reset occasionally as that is how IIS manages ASP.NET sites.

What you can also do is run a Windows Service with a WCF service that is always running. This service would listen to localhost on an endpoint only accessible from the same machine. You can then have the ASMX service call to the WCF service locally. This will allow you to always ensure your state is alive as long as you like even when IIS restarts the App Pool. Naturally, you can also change the security for the WCF Windows Service to allow access remotely with a password if you want to allow multiple web services to use the same service host for the purpose of improved resource usage.


Need Your Help

Controllers structuring in PHP frameworks

php zend-framework yii laravel

I'm going for an example to make the question easier:

Apache Spark Python to Scala translation

python hadoop apache-spark yarn pyspark

If I got it right Apache YARN receives Application Master and Node Manager as JAR files. They executed as Java process on the nodes of the YARN cluster.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.