By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,142 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,142 IT Pros & Developers. It's quick & easy.

Calling a Web Method do not change Web Service object state

P: n/a
I have a Web service that gets the financial periods and hold a reference to
a disconnected dataset built at initialization. Web methods work on the
dataset inside the web service. Everything is fine so far.

My problem is that when I call a web method to modify the dataset inside the
Web service it is never updated and I get no errors.

currentPeriods method will always give me 1 even if I call ChangeDataset and
call currentPeriods after.

Is this by design or I'm doing something wrong ?

Thanks.
'Simplified code here
Public Class Periods
Inherits System.Web.Services.WebService
Private thePeriods As DataSet

<WebMethod> _
Public Function currentPeriods() As DataSet
Return thePeriods
End Function

<WebMethod> _
Public Function ChangeDataset() As boolean
'update the dataset thePeriods column1 value =2
Return true
End Function

Public Function buildDataset() As boolean
'create the dataset theDS here with column1 value =1
thePeriods=theDS
End Function

Public Sub New()
buildDataset
End Sub

End Class
Dec 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Joe

Webmethods represent stateless calls. I.e. Each time you call a web
service, it gets instantiates, runs the web method, returns a result
and is then destroyed (along with any class variables like your
"thePeriods"). Therefore, each time you call a webmethod, your
initialize method is called and will create the dataset again and
again. Your update method is likely performing the dataset update
correctly, but the dataset is lost when the ChangeDataset webmethod
exits. When you call your currentPeriods method, it will be working
with a brand new dataset that has no record of your changes.

What you need to do is store you dataset in a statefull object
(something like and application variable) when you initialize it. After
that, you will need to modify your initializationroutine to check the
application variable and see if it holds your dataset. If it does, then
you need to work with that instance of it instead of creating a new
instance. All of your other methods should work with this application
variable to ensure that they are all working with same dataset.

Hope that help

Peter Kelcey

Dec 20 '05 #2

P: n/a
Hi Joe,

I think Peter's suggestion are reasonable. For webservice, generally we're
not recommended to include stateful data in XML webservice... However, if
you need to store such info in ASP.NET webservice so as to make it shared
to all the webmethods requests, we need to store it in a shared storage
which is application scope.... In ASP.NET, applicationState, application
cache or a certain class's static member variable are all the possible
approach for storing or referenceing such shared objects. Where do you
currently store the shared DataSet?

Regards,

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: Calling a Web Method do not change Web Service object state
Date: 20 Dec 2005 08:35:18 -0800
Organization: http://groups.google.com
Lines: 24
Message-ID: <11**********************@g47g2000cwa.googlegroups .com>
References: <49**********************************@microsoft.co m>
NNTP-Posting-Host: 66.203.207.7
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1135096523 16032 127.0.0.1 (20 Dec 2005
16:35:23 GMT)
X-Complaints-To: gr**********@google.com
NNTP-Posting-Date: Tue, 20 Dec 2005 16:35:23 +0000 (UTC)
In-Reply-To: <49**********************************@microsoft.co m>
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: g47g2000cwa.googlegroups.com; posting-host=66.203.207.7;
posting-account=GTafkQ0AAAC3ac_UHAsxZ5oy6zhk-wpe
Path:
TK2MSFTNGXA02.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!g47g2000cwa.googlegrou ps.com!not-for-mail
microsoft.public.dotnet.framework.webservices:1311 9
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Joe

Webmethods represent stateless calls. I.e. Each time you call a web
service, it gets instantiates, runs the web method, returns a result
and is then destroyed (along with any class variables like your
"thePeriods"). Therefore, each time you call a webmethod, your
initialize method is called and will create the dataset again and
again. Your update method is likely performing the dataset update
correctly, but the dataset is lost when the ChangeDataset webmethod
exits. When you call your currentPeriods method, it will be working
with a brand new dataset that has no record of your changes.

What you need to do is store you dataset in a statefull object
(something like and application variable) when you initialize it. After
that, you will need to modify your initializationroutine to check the
application variable and see if it holds your dataset. If it does, then
you need to work with that instance of it instead of creating a new
instance. All of your other methods should work with this application
variable to ensure that they are all working with same dataset.

Hope that help

Peter Kelcey
Dec 21 '05 #3

P: n/a
Thank you so much for your time guys. I knew it had to be something like
this, it's nice to hear it from someone else. I don't really need to share
my DS, so I will do something else. Thanks Peter and Steven, to share your
precious knowledge with all of us.

"Steven Cheng[MSFT]" wrote:
Hi Joe,

I think Peter's suggestion are reasonable. For webservice, generally we're
not recommended to include stateful data in XML webservice... However, if
you need to store such info in ASP.NET webservice so as to make it shared
to all the webmethods requests, we need to store it in a shared storage
which is application scope.... In ASP.NET, applicationState, application
cache or a certain class's static member variable are all the possible
approach for storing or referenceing such shared objects. Where do you
currently store the shared DataSet?

Regards,

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: Calling a Web Method do not change Web Service object state
Date: 20 Dec 2005 08:35:18 -0800
Organization: http://groups.google.com
Lines: 24
Message-ID: <11**********************@g47g2000cwa.googlegroups .com>
References: <49**********************************@microsoft.co m>
NNTP-Posting-Host: 66.203.207.7
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1135096523 16032 127.0.0.1 (20 Dec 2005
16:35:23 GMT)
X-Complaints-To: gr**********@google.com
NNTP-Posting-Date: Tue, 20 Dec 2005 16:35:23 +0000 (UTC)
In-Reply-To: <49**********************************@microsoft.co m>
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: g47g2000cwa.googlegroups.com; posting-host=66.203.207.7;
posting-account=GTafkQ0AAAC3ac_UHAsxZ5oy6zhk-wpe
Path:
TK2MSFTNGXA02.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!g47g2000cwa.googlegrou ps.com!not-for-mail
Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.webservices:1311 9
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Joe

Webmethods represent stateless calls. I.e. Each time you call a web
service, it gets instantiates, runs the web method, returns a result
and is then destroyed (along with any class variables like your
"thePeriods"). Therefore, each time you call a webmethod, your
initialize method is called and will create the dataset again and
again. Your update method is likely performing the dataset update
correctly, but the dataset is lost when the ChangeDataset webmethod
exits. When you call your currentPeriods method, it will be working
with a brand new dataset that has no record of your changes.

What you need to do is store you dataset in a statefull object
(something like and application variable) when you initialize it. After
that, you will need to modify your initializationroutine to check the
application variable and see if it holds your dataset. If it does, then
you need to work with that instance of it instead of creating a new
instance. All of your other methods should work with this application
variable to ensure that they are all working with same dataset.

Hope that help

Peter Kelcey

Dec 21 '05 #4

P: n/a
You're welcome Joe,

Feel free to post here when you need any further help.

Good luck!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
Thread-Topic: Calling a Web Method do not change Web Service object state
thread-index: AcYGMqVxwsNklPGRRQa719A4tsVTXw==
X-WBNR-Posting-Host: 204.101.63.162
From: "=?Utf-8?B?am9lYmxhc3Q=?=" <jo******@newsgroups.nospam>
References: <49**********************************@microsoft.co m>
<11**********************@g47g2000cwa.googlegroups .com>
<E1**************@TK2MSFTNGXA02.phx.gbl>
Subject: Re: Calling a Web Method do not change Web Service object state
Date: Wed, 21 Dec 2005 05:30:02 -0800
Lines: 82
Message-ID: <71**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.webservices
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.webservices:1314 2
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Thank you so much for your time guys. I knew it had to be something like
this, it's nice to hear it from someone else. I don't really need to share
my DS, so I will do something else. Thanks Peter and Steven, to share your
precious knowledge with all of us.

"Steven Cheng[MSFT]" wrote:
Hi Joe,

I think Peter's suggestion are reasonable. For webservice, generally we're not recommended to include stateful data in XML webservice... However, if you need to store such info in ASP.NET webservice so as to make it shared
to all the webmethods requests, we need to store it in a shared storage
which is application scope.... In ASP.NET, applicationState, application cache or a certain class's static member variable are all the possible
approach for storing or referenceing such shared objects. Where do you
currently store the shared DataSet?

Regards,

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: Calling a Web Method do not change Web Service object state
Date: 20 Dec 2005 08:35:18 -0800
Organization: http://groups.google.com
Lines: 24
Message-ID: <11**********************@g47g2000cwa.googlegroups .com>
References: <49**********************************@microsoft.co m>
NNTP-Posting-Host: 66.203.207.7
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1135096523 16032 127.0.0.1 (20 Dec 2005
16:35:23 GMT)
X-Complaints-To: gr**********@google.com
NNTP-Posting-Date: Tue, 20 Dec 2005 16:35:23 +0000 (UTC)
In-Reply-To: <49**********************************@microsoft.co m>
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: g47g2000cwa.googlegroups.com; posting-host=66.203.207.7;
posting-account=GTafkQ0AAAC3ac_UHAsxZ5oy6zhk-wpe
Path:
TK2MSFTNGXA02.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!g47g2000cwa.googlegrou ps.com!not-for-mail
Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.webservices:1311 9
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Joe

Webmethods represent stateless calls. I.e. Each time you call a web
service, it gets instantiates, runs the web method, returns a result
and is then destroyed (along with any class variables like your
"thePeriods"). Therefore, each time you call a webmethod, your
initialize method is called and will create the dataset again and
again. Your update method is likely performing the dataset update
correctly, but the dataset is lost when the ChangeDataset webmethod
exits. When you call your currentPeriods method, it will be working
with a brand new dataset that has no record of your changes.

What you need to do is store you dataset in a statefull object
(something like and application variable) when you initialize it. After
that, you will need to modify your initializationroutine to check the
application variable and see if it holds your dataset. If it does, then
you need to work with that instance of it instead of creating a new
instance. All of your other methods should work with this application
variable to ensure that they are all working with same dataset.

Hope that help

Peter Kelcey


Dec 21 '05 #5

P: n/a
No problem Joe, good luck.

joeblast wrote:
Thank you so much for your time guys. I knew it had to be something like
this, it's nice to hear it from someone else. I don't really need to share
my DS, so I will do something else. Thanks Peter and Steven, to share your
precious knowledge with all of us.

"Steven Cheng[MSFT]" wrote:
Hi Joe,

I think Peter's suggestion are reasonable. For webservice, generally we're
not recommended to include stateful data in XML webservice... However, if
you need to store such info in ASP.NET webservice so as to make it shared
to all the webmethods requests, we need to store it in a shared storage
which is application scope.... In ASP.NET, applicationState, application
cache or a certain class's static member variable are all the possible
approach for storing or referenceing such shared objects. Where do you
currently store the shared DataSet?

Regards,

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: Calling a Web Method do not change Web Service object state
Date: 20 Dec 2005 08:35:18 -0800
Organization: http://groups.google.com
Lines: 24
Message-ID: <11**********************@g47g2000cwa.googlegroups .com>
References: <49**********************************@microsoft.co m>
NNTP-Posting-Host: 66.203.207.7
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1135096523 16032 127.0.0.1 (20 Dec 2005
16:35:23 GMT)
X-Complaints-To: gr**********@google.com
NNTP-Posting-Date: Tue, 20 Dec 2005 16:35:23 +0000 (UTC)
In-Reply-To: <49**********************************@microsoft.co m>
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: g47g2000cwa.googlegroups.com; posting-host=66.203.207.7;
posting-account=GTafkQ0AAAC3ac_UHAsxZ5oy6zhk-wpe
Path:
TK2MSFTNGXA02.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!g47g2000cwa.googlegrou ps.com!not-for-mail
Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.webservices:1311 9
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Joe

Webmethods represent stateless calls. I.e. Each time you call a web
service, it gets instantiates, runs the web method, returns a result
and is then destroyed (along with any class variables like your
"thePeriods"). Therefore, each time you call a webmethod, your
initialize method is called and will create the dataset again and
again. Your update method is likely performing the dataset update
correctly, but the dataset is lost when the ChangeDataset webmethod
exits. When you call your currentPeriods method, it will be working
with a brand new dataset that has no record of your changes.

What you need to do is store you dataset in a statefull object
(something like and application variable) when you initialize it. After
that, you will need to modify your initializationroutine to check the
application variable and see if it holds your dataset. If it does, then
you need to work with that instance of it instead of creating a new
instance. All of your other methods should work with this application
variable to ensure that they are all working with same dataset.

Hope that help

Peter Kelcey


Dec 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.