Is a .NET web service created with every method call?

I am trying to use web services for an idea that I had. Running debugging looks like the web service creates an instance every time the client calls the method in the web service. I see this, seeing that the constructor gets called every time I call the method. I only create an instance of the proxy web service once in the client.

This would mean that I would need to store all the data between calls and means that if I use a database, I will have to reconnect for each method call.

It can't be right?

+7
web-services
source share
3 answers

For ASMX, this is correct and pretty much good. Services should be as stateless as possible, and if you really need to store something between calls, you can use a singleton. I don’t think that keeping a database connection would be qualified because they are cached and you still want to use your use.

If you want one object to stay alive between calls, WCF offers this option. Given that ASMX is out of date, you can go to WCF.

+3
source share

This is really correct.

Web services (in a service-oriented architecture) are designed to be stateless (they don’t remember anything between calls ... all data is resistant to you).

If you search the Internet long enough, you will find attempts to create stateful web services (which have their place, but go against the basic principles of SOA). However, you will find that they do not mitigate your problems. You will receive a new combination of instant exchange with each call, and any connections to the database will need to be restored.

+5
source share

Yes, this is 100% correct. Each time a request is received by the server, a new object is created to process the request in a separate thread.

This is the same thing that happens with the ASP.NET base web form.

+2
source share

All Articles