all groups > dotnet web services > april 2005 >
You're in the

dotnet web services

group:

My WebService Seems to be Loading Everytime it is invoked


My WebService Seems to be Loading Everytime it is invoked Harry Whitehouse
4/22/2005 6:42:27 PM
dotnet web services:
I'm coming from an ISAPI background and migrating code to Webservices.

In the ISAPI world, there are sections of code that are invoked only once
when the DLL is loaded by IIS. It's a place where you can do time-consuming
resource loading once and only once.

In .NET Webservices, I figured that the section at the bottom of this
message would be called once upon the loading of the Webservice. From that
point on, only the methods exposed in the service would be invoked. At
least that was my theory.

Now perhaps this is a lack of understanding of how the ASPNET services load.
In the ISAPI world, the first time the ISAPI module is invoked it generally
stays in IIS memory until you end or restart IIS services (an option to
"cache ISAPI services". That is for speed in a production environment.
This can be a pain in the butt when you are debugging, since you have to
stop/start IIS every time you compile and link a revision.

In .NET, I notice that I can always rebuild my Webservice without restarting
IIS and perhaps that means ASPNET by default doesn't stay in memory after
invocation.

So my question is this: Is there a similar caching option for ASPNET
services or does that startup code invoke everytime someone hits a
Webmethod?

TIA

Harry

public Service1()
{

InitializeComponent();

}

Re: My WebService Seems to be Loading Everytime it is invoked Harry Whitehouse
4/23/2005 7:57:02 AM
Thank you Sami!!!

Harry

Re: My WebService Seems to be Loading Everytime it is invoked Sami Vaaraniemi
4/23/2005 11:40:29 AM
[quoted text, click to view]

ASP.NET Web Services are by default stateless. That's a fancy way of saying
that each call to a Web Service method creates a new instance of the Web
Service class which knows nothing of previous calls unless you specifically
implement it somehow. That's why the constructor is invoked every time
someone hits a Web method.

That said, one-time initialization can be done in the Application_Start
handler in the Global class. Web Services can also be made stateful by using
cookies and session state, the price being that the service will then be
less scalable.

When you recompile the Web Service, ASP.NET detects that it has changed and
restarts the application automatically without requiring you to restart IIS.

Regards,
Sami

AddThis Social Bookmark Button