开发者

Understanding Asp.net web service

开发者 https://www.devze.com 2023-01-30 10:57 出处:网络
Can you please answer to the following questions to en开发者_如何学Clighten me about web services.

Can you please answer to the following questions to en开发者_如何学Clighten me about web services.

  1. What is the lifecycle of web service ? When the class which represents my web service gets instanced and when it's start running (executing) ?

  2. Is it there new instance created for every webMethod call ? And what happens if there are multiple simultaneous requests for same or different web method ?

  3. When to open connection to remote resource, that the onnection is ready before any requests. And this connection must persist through whole lifetime of web service.

Thank you in advace for all answers.


Webservices are nothing more than ASP.NET pages communicating on the SOAP protocol (XML over HTTP). Each method have its own round-trip (like a page, so new instances are created by default). ASP.NET thread pool is used for running a webservice. As web programmer you don't have lot of control over how thread pool is used since it depends on many external factors (system resources, concurrent page requests...).

If you mean database connections by 'Opening connection to remote resources' these connections also are pooled by Connection Pool of ADO.NET and it will be managed automatically. If you external resources are heavy use Singleton webservice model and load external resources in constructor. Don't use singleton patteron on a database connection (It has its own pooling mechanism). You should take care of concurrency issues for your static variables if you are choosing Singleton pattern.

At the end I should say living in managed-world of programming is easier than ever. Most of the time somebody is caring about our doubts.


  1. That depends; You have two instancation models.

    • "Single Call" (an instance is created for each call made to the service)
    • "Singleton" (an instance is created on the first call and reused as long as the process remains alive).
  2. See answer 1; Eleboration; Yes, each call get's its own instance

  3. I would seperate that away from the actual Web Service class. You can use another singleton approach to achieve this functionality.

Hope this helps,

0

精彩评论

暂无评论...
验证码 换一张
取 消