473,230 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

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

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.
Jun 12 '07 #1
2 1612
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]
- mv*@spam.guard.caspershouse.com

"BLUE" <bluewrote in message news:ex**************@TK2MSFTNGP04.phx.gbl...
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.

Jun 12 '07 #2
Hi,
"BLUE" <bluewrote in message news:ex**************@TK2MSFTNGP04.phx.gbl...
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???

Cause in a webservice escenario is like if you are using the SAME
executable.

Imagine that in your win apps bith apps use a third app (think of it as a
hidden app) that is where is hosted the classes you are using

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???
Wrong, if you see the docs you will see that the webservice is created by
the IIS as a SINGLETON, so all the calling clients will share the same copy.
Jun 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: baumann | last post by:
hi all, according the private / protected access control, - private; that is, its name can be used only by members and friends of the class in which it is declared. - protected; that is,...
2
by: Jonas Cord | last post by:
Hi, I'm trying to learn proxy classes in C++ so I've written the following code, trying to modify an example given in Deitel & Deitel's C++ book. I am trying to "hide" details of the original...
33
by: Chris Capel | last post by:
What is the rationale behind the decision not to allow abstract static class members? It doesn't seem like it's a logically contradictory concept, or that the implementation would be difficult or...
9
by: Joanna Carter \(TeamB\) | last post by:
Following on from the other discussion, I have to just check something out with reference to disposal of resources held in static fields. I have a Persistence Framework that is 'globally...
7
by: Atul Malaviya | last post by:
>From a design/usability perspective. When will one use a singleton pattern and when a class with purely static members? What are the pros and cons? I have inherited a code base which is full...
3
by: mark.norgate | last post by:
Hello I'm writing an application in ASP.NET 1.1 and have come across a problem using static fields in my page classes. I have lots of controls on the page that all need to bind to the same...
2
by: utab | last post by:
Dear all, I am confused at some point on the initialization of static map member of a class. The class I have designed id something like this. class Class_name{ public: private:
9
by: wizwx | last post by:
There are two typical implementations of a singleton. The first one is to use a static pointer class Singleton { static Singleton * pSingleton; public: static Singleton * instance() {...
10
by: JoeC | last post by:
I have been programming for a while and I have seen this syntax before and I copied this from a book but the book didn't explain what is going on here. class engine{ protected: static engine*...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.