473,396 Members | 1,774 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,396 software developers and data experts.

Static Constructor & webservice

Hi,

How long do webservice objects live for? In particular, if i have static
variables filled with data from a static constructor in a webservice, how
long will that data persist?

thxs
Nov 23 '05 #1
5 6244
Webservices are stateless objects. This means that as soon as your
webmethod completes and returns to the calling client, then you class
variables are lost. Each call to your webservice instantiates a new
object. (Unless you start fooling around with using the session object
in your services to maintain data between calls.)

That is why service design requires a different frame of thought than
standard component design. With standard component design, you can pass
in parameters to a constructor and then reference those values later on
in various method calls. You can essential pass in your parameters in
pieces using multiple calls. With service design, you should pass in
all the parameters at once to your webmethod so that it will have all
of the information it needs to complete its tasks.

Peter Kelcey

Nov 23 '05 #2
Thanks for Peter's inputs.

Hi mfc_mobile,

As Peter has mentioned, such things like "SessionState", "object instance
lifecycle..." or "static constructors or members" are all implementation
specific. From standard XML Webservice perspective, they're all transparent
to the webservice consumers, we should not reply on them when programming
through webservice.

As for your question, the .NET ASP.NET webservice implementation host the
webservice object instance in asp.net application (AppDomain). So the
webservice object/class and their static members are all available in the
application's AppDomain. Also, the static constructor will be called once
per Appdomain. For the webservice instance's lifecycle, it's hard to say,
because anytime when the instance is no longer used and being idle for long
time, runtime may release its reference and collect it.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
From: "Peter Kelcey" <Pe**********@telus.com>
Newsgroups: microsoft.public.dotnet.framework.webservices
Subject: Re: Static Constructor & webservice
Date: 7 Nov 2005 11:37:51 -0800
Organization: http://groups.google.com
Lines: 16
Message-ID: <11**********************@g49g2000cwa.googlegroups .com>
References: <u#**************@TK2MSFTNGP09.phx.gbl>
NNTP-Posting-Host: 38.112.12.110
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1131392276 14853 127.0.0.1 (7 Nov 2005 19:37:56
GMT)
X-Complaints-To: gr**********@google.com
NNTP-Posting-Date: Mon, 7 Nov 2005 19:37:56 +0000 (UTC)
In-Reply-To: <u#**************@TK2MSFTNGP09.phx.gbl>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET
CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.40607),gzip(gfe),gzip(gfe)
Complaints-To: gr**********@google.com
Injection-Info: g49g2000cwa.googlegroups.com; posting-host=38.112.12.110;
posting-account=GTafkQ0AAAC3ac_UHAsxZ5oy6zhk-wpe
Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!border2.nntp.dca.giganews.com!border1.nntp.d ca.giganews.com!nntp.gigan
ews.com!postnews.google.com!g49g2000cwa.googlegrou ps.com!not-for-mail
microsoft.public.dotnet.framework.webservices:8515
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Webservices are stateless objects. This means that as soon as your
webmethod completes and returns to the calling client, then you class
variables are lost. Each call to your webservice instantiates a new
object. (Unless you start fooling around with using the session object
in your services to maintain data between calls.)

That is why service design requires a different frame of thought than
standard component design. With standard component design, you can pass
in parameters to a constructor and then reference those values later on
in various method calls. You can essential pass in your parameters in
pieces using multiple calls. With service design, you should pass in
all the parameters at once to your webmethod so that it will have all
of the information it needs to complete its tasks.

Peter Kelcey
Nov 23 '05 #3
Hi mfc_mobile,

Have you got any further ideas on this or does the things in our last reply
helps a little? If there're anything else we can help, please feel free to
post here. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
X-Tomcat-ID: 68687518
References: <u#**************@TK2MSFTNGP09.phx.gbl>
<11**********************@g49g2000cwa.googlegroups .com>
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----=_NextPart_0001_876B59EB"
Content-Transfer-Encoding: 7bit
From: st*****@online.microsoft.com (Steven Cheng[MSFT])
Organization: Microsoft
Date: Tue, 08 Nov 2005 03:28:56 GMT
Subject: Re: Static Constructor & webservice
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
Message-ID: <RB**************@TK2MSFTNGXA01.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.webservices
Lines: 184
Path: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.webservices:8522
NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182

Thanks for Peter's inputs.

Hi mfc_mobile,

As Peter has mentioned, such things like "SessionState", "object instance
lifecycle..." or "static constructors or members" are all implementation
specific. From standard XML Webservice perspective, they're all transparent
to the webservice consumers, we should not reply on them when programming
through webservice.

As for your question, the .NET ASP.NET webservice implementation host the
webservice object instance in asp.net application (AppDomain). So the
webservice object/class and their static members are all available in the
application's AppDomain. Also, the static constructor will be called once
per Appdomain. For the webservice instance's lifecycle, it's hard to say,
because anytime when the instance is no longer used and being idle for long
time, runtime may release its reference and collect it.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
From: "Peter Kelcey" <Pe**********@telus.com>
Newsgroups: microsoft.public.dotnet.framework.webservices
Subject: Re: Static Constructor & webservice
Date: 7 Nov 2005 11:37:51 -0800
Organization: http://groups.google.com
Lines: 16
Message-ID: <11**********************@g49g2000cwa.googlegroups .com>
References: <u#**************@TK2MSFTNGP09.phx.gbl>
NNTP-Posting-Host: 38.112.12.110
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1131392276 14853 127.0.0.1 (7 Nov 2005 19:37:56
GMT)
X-Complaints-To: gr**********@google.com
NNTP-Posting-Date: Mon, 7 Nov 2005 19:37:56 +0000 (UTC)
In-Reply-To: <u#**************@TK2MSFTNGP09.phx.gbl>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET
CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.40607),gzip(gfe),gzip(gfe)
Complaints-To: gr**********@google.com
Injection-Info: g49g2000cwa.googlegroups.com; posting-host=38.112.12.110;
posting-account=GTafkQ0AAAC3ac_UHAsxZ5oy6zhk-wpe
Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!border2.nntp.dca.giganews.com!border1.nntp.d ca.giganews.com!nntp.gigan
ews.com!postnews.google.com!g49g2000cwa.googlegrou ps.com!not-for-mail
microsoft.public.dotnet.framework.webservices:8515
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Webservices are stateless objects. This means that as soon as your
webmethod completes and returns to the calling client, then you class
variables are lost. Each call to your webservice instantiates a new
object. (Unless you start fooling around with using the session object
in your services to maintain data between calls.)

That is why service design requires a different frame of thought than
standard component design. With standard component design, you can pass
in parameters to a constructor and then reference those values later on
in various method calls. You can essential pass in your parameters in
pieces using multiple calls. With service design, you should pass in
all the parameters at once to your webmethod so that it will have all
of the information it needs to complete its tasks.

Peter Kelcey


Nov 23 '05 #4
Thanks for your replies, sorry I didn't answer before.

I've already told my boss theres no easy way of doing this. The app we have
requires initialising with a lot of static data per webservice call. It just
seemed more efficient to cache that data somewhere. Currently its not a big
issue for us because the rest of the processing takes proportionally much
more time than the initial setup time we need to get the static data. I
think if it does become an issue, its probably easier for us and allow us
more control if we just create a object and attach it to a control
application to keep the static data alive.
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:ko**************@TK2MSFTNGXA02.phx.gbl...
Hi mfc_mobile,

Have you got any further ideas on this or does the things in our last
reply
helps a little? If there're anything else we can help, please feel free to
post here. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
X-Tomcat-ID: 68687518
References: <u#**************@TK2MSFTNGP09.phx.gbl>
<11**********************@g49g2000cwa.googlegroups .com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_0001_876B59EB"
Content-Transfer-Encoding: 7bit
From: st*****@online.microsoft.com (Steven Cheng[MSFT])
Organization: Microsoft
Date: Tue, 08 Nov 2005 03:28:56 GMT
Subject: Re: Static Constructor & webservice
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
Message-ID: <RB**************@TK2MSFTNGXA01.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.webservices
Lines: 184
Path: TK2MSFTNGXA01.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.webservices:8522
NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182

Thanks for Peter's inputs.

Hi mfc_mobile,

As Peter has mentioned, such things like "SessionState", "object instance
lifecycle..." or "static constructors or members" are all implementation
specific. From standard XML Webservice perspective, they're all
transparent
to the webservice consumers, we should not reply on them when programming
through webservice.

As for your question, the .NET ASP.NET webservice implementation host the
webservice object instance in asp.net application (AppDomain). So the
webservice object/class and their static members are all available in the
application's AppDomain. Also, the static constructor will be called once
per Appdomain. For the webservice instance's lifecycle, it's hard to say,
because anytime when the instance is no longer used and being idle for
long
time, runtime may release its reference and collect it.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
From: "Peter Kelcey" <Pe**********@telus.com>
Newsgroups: microsoft.public.dotnet.framework.webservices
Subject: Re: Static Constructor & webservice
Date: 7 Nov 2005 11:37:51 -0800
Organization: http://groups.google.com
Lines: 16
Message-ID: <11**********************@g49g2000cwa.googlegroups .com>
References: <u#**************@TK2MSFTNGP09.phx.gbl>
NNTP-Posting-Host: 38.112.12.110
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1131392276 14853 127.0.0.1 (7 Nov 2005
19:37:56
GMT)
X-Complaints-To: gr**********@google.com
NNTP-Posting-Date: Mon, 7 Nov 2005 19:37:56 +0000 (UTC)
In-Reply-To: <u#**************@TK2MSFTNGP09.phx.gbl>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET
CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.40607),gzip(gfe),gzip(gfe)
Complaints-To: gr**********@google.com
Injection-Info: g49g2000cwa.googlegroups.com; posting-host=38.112.12.110;
posting-account=GTafkQ0AAAC3ac_UHAsxZ5oy6zhk-wpe
Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!border2.nntp.dca.giganews.com!border1.nntp.d ca.giganews.com!nntp.gigan
ews.com!postnews.google.com!g49g2000cwa.googlegrou ps.com!not-for-mail
Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.webservices:8515
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Webservices are stateless objects. This means that as soon as your
webmethod completes and returns to the calling client, then you class
variables are lost. Each call to your webservice instantiates a new
object. (Unless you start fooling around with using the session object
in your services to maintain data between calls.)

That is why service design requires a different frame of thought than
standard component design. With standard component design, you can pass
in parameters to a constructor and then reference those values later on
in various method calls. You can essential pass in your parameters in
pieces using multiple calls. With service design, you should pass in
all the parameters at once to your webmethod so that it will have all
of the information it needs to complete its tasks.

Peter Kelcey

Nov 23 '05 #5
Thanks for your followup.

Well, if you meet any further problem need assitance, please feel free to
post here.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
From: <mf********@newsgroup.nospam>
References: <u#**************@TK2MSFTNGP09.phx.gbl>
<11**********************@g49g2000cwa.googlegroups .com>
<RB**************@TK2MSFTNGXA01.phx.gbl>
<ko**************@TK2MSFTNGXA02.phx.gbl>
Subject: Re: Static Constructor & webservice
Date: Mon, 14 Nov 2005 16:58:35 -0000
Lines: 131
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
Message-ID: <eV**************@TK2MSFTNGP15.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.webservices
NNTP-Posting-Host: 83.244.128.126
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
microsoft.public.dotnet.framework.webservices:1272 0
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Thanks for your replies, sorry I didn't answer before.

I've already told my boss theres no easy way of doing this. The app we have
requires initialising with a lot of static data per webservice call. It
just
seemed more efficient to cache that data somewhere. Currently its not a big
issue for us because the rest of the processing takes proportionally much
more time than the initial setup time we need to get the static data. I
think if it does become an issue, its probably easier for us and allow us
more control if we just create a object and attach it to a control
application to keep the static data alive.
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:ko**************@TK2MSFTNGXA02.phx.gbl...
Hi mfc_mobile,

Have you got any further ideas on this or does the things in our last
reply
helps a little? If there're anything else we can help, please feel free to
post here. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
X-Tomcat-ID: 68687518
References: <u#**************@TK2MSFTNGP09.phx.gbl>
<11**********************@g49g2000cwa.googlegroups .com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_0001_876B59EB"
Content-Transfer-Encoding: 7bit
From: st*****@online.microsoft.com (Steven Cheng[MSFT])
Organization: Microsoft
Date: Tue, 08 Nov 2005 03:28:56 GMT
Subject: Re: Static Constructor & webservice
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
Message-ID: <RB**************@TK2MSFTNGXA01.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.webservices
Lines: 184
Path: TK2MSFTNGXA01.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.webservices:8522
NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182

Thanks for Peter's inputs.

Hi mfc_mobile,

As Peter has mentioned, such things like "SessionState", "object instance
lifecycle..." or "static constructors or members" are all implementation
specific. From standard XML Webservice perspective, they're all
transparent
to the webservice consumers, we should not reply on them when programming
through webservice.

As for your question, the .NET ASP.NET webservice implementation host the
webservice object instance in asp.net application (AppDomain). So the
webservice object/class and their static members are all available in the
application's AppDomain. Also, the static constructor will be called once
per Appdomain. For the webservice instance's lifecycle, it's hard to say,
because anytime when the instance is no longer used and being idle for
long
time, runtime may release its reference and collect it.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
From: "Peter Kelcey" <Pe**********@telus.com>
Newsgroups: microsoft.public.dotnet.framework.webservices
Subject: Re: Static Constructor & webservice
Date: 7 Nov 2005 11:37:51 -0800
Organization: http://groups.google.com
Lines: 16
Message-ID: <11**********************@g49g2000cwa.googlegroups .com>
References: <u#**************@TK2MSFTNGP09.phx.gbl>
NNTP-Posting-Host: 38.112.12.110
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1131392276 14853 127.0.0.1 (7 Nov 2005
19:37:56
GMT)
X-Complaints-To: gr**********@google.com
NNTP-Posting-Date: Mon, 7 Nov 2005 19:37:56 +0000 (UTC)
In-Reply-To: <u#**************@TK2MSFTNGP09.phx.gbl>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET
CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.40607),gzip(gfe),gzip(gfe)
Complaints-To: gr**********@google.com
Injection-Info: g49g2000cwa.googlegroups.com; posting-host=38.112.12.110;
posting-account=GTafkQ0AAAC3ac_UHAsxZ5oy6zhk-wpe
Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli ne.de!border2.nntp.dca.giganews.com!border1.nntp.d ca.giganews.com!nntp.gigan ews.com!postnews.google.com!g49g2000cwa.googlegrou ps.com!not-for-mail
Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.webservices:8515
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Webservices are stateless objects. This means that as soon as your
webmethod completes and returns to the calling client, then you class
variables are lost. Each call to your webservice instantiates a new
object. (Unless you start fooling around with using the session object
in your services to maintain data between calls.)

That is why service design requires a different frame of thought than
standard component design. With standard component design, you can pass
in parameters to a constructor and then reference those values later on
in various method calls. You can essential pass in your parameters in
pieces using multiple calls. With service design, you should pass in
all the parameters at once to your webmethod so that it will have all
of the information it needs to complete its tasks.

Peter Kelcey


Nov 23 '05 #6

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

Similar topics

4
by: TS | last post by:
I am trying to add an event handler for a static variable of a class and i can't figure out how to do so since the class is never instantiated. The wmp variable gets instantiated when my code...
4
by: MPF | last post by:
When designing a n-tier architecture, what is the preferred method/function accessibility? <Specifically for asp.net apps> A private constructor and shared/static methods & functions? A public...
4
by: indigator | last post by:
I have an ASP.Net web service class, DataLayer.asmx.cs. I have two constructors for the DataLayer class. One is the default parameter-less one and the second one accepts a string argument. When I...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
4
by: mnowosad | last post by:
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,...
7
by: Morgan Cheng | last post by:
In the book *Programming C#* 4th editionby Jesse Liberty, it reads "Actually, the CLR guarantees to start running the static constructor before anything else is done with your class. However, it...
9
by: None | last post by:
Hi, I'm facing a problem with static instances. I have created a class called CustomList by deriving the class List<int>. Inside the CustomList i have created Remove event (when any item is...
2
by: mark4asp | last post by:
Q: Initialising and updating a class with only static members & database dependency I have a class with the following members: public static List<ACISACIS_List; static AssetClass() { //...
19
by: Steven Blair | last post by:
Hi, I have webservice which holds a static variable. I send my first message into the webservice and the static variable gets a value. If I queried the webservice at a later time (say after 1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.