2

Can you please answer to the following questions to enlighten 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.

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I need WMI connection and connection to vmware vCenter server. I guess ADO.net don't take care for this. Do you have any example of this Singelton pattern.
0
  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,

1 Comment

"I would seperate that away from the actual Web Service class. You can use another singleton approach to achieve this functionality." When to instantine this singelton that connection becoms available before first webMethod call ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.