The static variables I am using are declared as readonly. So multi-threading
is not an issue here. But they DO have an expensive initialization process
(placed in the static constructor), which is the reason why I do not want
this initialization to happen upon each web method request.
Notice that this issue (static constructor of the web service class being
executed for every web method request) has already been reported in a C-Sharp
Corner article. The guy even created a helper class (Pool) to go around this
problem (a solution that did not please me). See link below:
http://www.c-sharpcorner.com/UploadF...LDatabase.aspx
Is there anything in the web service declaration that could be causing the
AppDomain to be created in each web method request? I created the web service
class using Visual Studio 2005 wizard and did not modify the generated
template (only added my web methods).
Thanks,
Marcos
"John Saunders" wrote:
"mnowosad" <mn******@discussions.microsoft.comwrote in message
news:B8**********************************@microsof t.com...
As far I know, static variables are tied to AppDomain scopes. So, every
time
an executing code within an AppDomain references a class for the the first
time since the AppDomain was created/loaded, the .NET executes the
assignments done in the class static variables declarations and runs the
static constructor of that class.
So, I expected that, as in ASP.NET web site, for a given Web Service site,
the AppDomain would be initialized upon the first request for a web method
and, after that, the following web method requests would execute under the
same AppDomain. That would mean that static variables defined in a Web
Service class could share theri values across web method requests.
However, what I am noticing in my code is that the static variables
initialization and the static constructor are being executed in every
single
web method request! What that means? Is the AppDomain under which web
service
runs being created/loaded upon each web method request and being unloaded
after the web method processing is done?? That sounds like a huge
overhead.
First of all, they should not be happening on each web method request,
unless that request is forcing the creation of a new AppDomain.
Second, I hope you know that you have to synchronize write access to these
statics, as they can be referenced by multiple threads (requests) at the
same time.
John