Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web service variable shared for the lifetime of the webservice?

How can I make a variable (object) available for the whole lifetime of the webservice?

Static variable seem to work but is there an other way to do it?

like image 975
Patrick Desjardins Avatar asked Dec 22 '22 13:12

Patrick Desjardins


1 Answers

Static variables exist for the lifetime of the App Domain that contains them. In the case of a web service, this is usually the ASP.Net Worker Process. What that means is that when IIS decides to cycle the worker process, your static variable will be gone. This may be what you want, in which case it is probably a good choice. (Putting asside discussions of whether or not static variables are proper in a given context).

Within the scope of a web service you also have access to the HttpApplicationState via the Application property (this would be an asmx service...not sure if WCF is the same or not), so this could also be a good choice for stashing something needed for the lifetime of a service.

like image 107
ckramer Avatar answered May 05 '23 02:05

ckramer