Re: Going crazy trying to understand Web Services behaviour with static member fields, static classes and singleton classes.



That is not the case. In a Web Service hosted in ASP.NET, the assembly
is loaded for the life of the app domain (ASP.NET can recycle the app domain
mind you) and therefore the static values will exist for the life of the app
domain.

It doesn't seem like you would want this kind of functionality, because
the lifecycle of a user's interaction with your app goes beyond one single
page request. I imagine that a user will use multiple pages throughout
their session.

If you want to equate user sessions with the experience in a single run
of a Windows Forms app, then you can't use static members. The class would
have to contain the value in the instance, and then you would have to have
specific instances for each session on the webserver.

For windows forms apps, using static works because there is only one
session. Unfortunately, that is not the case with a web service/web app in
general.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"BLUE" <blue> wrote in message news:exD7$hRrHHA.4804@xxxxxxxxxxxxxxxxxxxxxxx
FirstClass members:
- static int counter;
- SingletonClass sc = SingletonClass.Instance;

Moreovere FirstClass uses a static class named SecondClass with a static
property SecondClass.Description.


In a normal windows application:
- if in the Main method I create 2 or more instances of FirstClass, they
all see the same counter, the same SingletonClass.Instance and the same
SecondClass.Description
- if I launch the exe 2 or more times each exe sees different things


What does it happen with web services???

I think a web service is like a web page, so it lives only for the
duration of the execution of a webmethod like an exe lives only until we
click on the x: each call should reset counter to 0 so but this is not
true!
Why???

Logging on a text file I have discovered that two sequential calls to the
same web method refers to the same SingletonClass.Instance so I've thought
that I can declare a static DateTime and execute a method only if last
call was 24 hours ago.
To my surprise that DateTime is reset on each subsequent call but not if
two calls are simultaneous.

I do not understand what is the exact behaviour of Web Services:
subsequent calls are like 2 launch of the same exe and simultaneous ones
like 2 creation of FirstClass from the Main method?


Thanks,
Luigi.



.



Relevant Pages

  • Re: Are ASP.NET user interfaces essentially dead now?
    ... it will be tight enough that you can't call SQL ... takes longer to develop ASP.NET interface than a windowsform app ... And communicating with a Web Service is not required the ... > I see Winforms doing the major amount of interface work and leaving the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: SSL for very simple security need in web service app
    ... There is only a single end point here, a web service ... app that simply takes order info, validates it and applies it to a database. ... this is a common scenario. ... >>> userID ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Cant find item in server side cache
    ... Then I used the url for web service when it was originally created which was ... So the web service and aspx ... page really were running in different instances of the web app. ... the web service returns the GUID back to the winform via the WS ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: The SA Mess
    ... The app is obfuscated. ... Shift to .NET talking to a SQL db on the local network, ... have a dog. ... Go through a web service on top of all of that, ...
    (microsoft.public.sqlserver.security)
  • Re: CodeDom V Emit with Dynamic Proxy
    ... .NET assemblies are never unloaded unless you unload ... service client and marshaled the calls between my main app domain and the ... A product we need to integrate with exposes a web service BUT its methods ...
    (microsoft.public.dotnet.framework.clr)