473,503 Members | 12,791 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retaining data between web service calls

RJ
I tried using the Application object to store data in some variables, which
would be globally accessible within the web service application code. On
subsequent web method calls, the Application object no longer contains the
variables I added. Is the Application object supposed to work the way it
does in a web page?

I was just attempting to read the web.config file once at startup. Now I am
just reading the web.config file in every web method, on every call to the
web service. Should I have to do this? Thanks for any insights.

RJ
Nov 21 '05 #1
5 3788

"RJ" <RJ@PostOnly.com> wrote in message
news:uB**************@tk2msftngp13.phx.gbl...
I tried using the Application object to store data in some variables, which would be globally accessible within the web service application code. On
subsequent web method calls, the Application object no longer contains the
variables I added. Is the Application object supposed to work the way it
does in a web page?

I was just attempting to read the web.config file once at startup. Now I am just reading the web.config file in every web method, on every call to the
web service. Should I have to do this? Thanks for any insights.

RJ


The Application object should work the same way it works in any ASP.NET
application: the values stored in it are remembered from request to request.
The Application object loses the values when the application restarts. Are
you sure the application is not restarting between calls for some reason?
Btw there is no need for you to enable SessionState in order to use the
Application object.

I did a small test with this web method:

[WebMethod]
public int TestApplicationState()
{
if (Application["MyKey"] == null)
{
Application["MyKey"] = 0;
}

int value = (int)Application["MyKey"] + 1;
Application["MyKey"] = value;
return value;
}

Subsequent calls from my client to the above web method return values 1, 2,
3... as expected. (Note that the code is not thread safe but that's another
story).

Regards
Sami
Nov 21 '05 #2
RJ
Sami,
Thanks for performing the test. I have not enabled SessionState. I am
simply adding values to the Application object in the Application_Start
event handler method. Seconds later, I call other web methods in this web
service, which attempt to access the Application object by key ( Dim myVar
as String = Me.Application("Name") .... in VB.NET)
I immediately print out the value of myVar and it is never set. I am
assuming that Application_Start is called once before the first call to any
web method? Is this approach sound, or should I add the values to the
Application object somewhere else in the web service code?

"Sami Vaaraniemi" <sa**********@pleasejippii.fi> wrote in message
news:OU*************@TK2MSFTNGP09.phx.gbl...

"RJ" <RJ@PostOnly.com> wrote in message
news:uB**************@tk2msftngp13.phx.gbl...
I tried using the Application object to store data in some variables, which
would be globally accessible within the web service application code. On subsequent web method calls, the Application object no longer contains the variables I added. Is the Application object supposed to work the way it does in a web page?

I was just attempting to read the web.config file once at startup. Now I am
just reading the web.config file in every web method, on every call to
the web service. Should I have to do this? Thanks for any insights.

RJ


The Application object should work the same way it works in any ASP.NET
application: the values stored in it are remembered from request to

request. The Application object loses the values when the application restarts. Are
you sure the application is not restarting between calls for some reason?
Btw there is no need for you to enable SessionState in order to use the
Application object.

I did a small test with this web method:

[WebMethod]
public int TestApplicationState()
{
if (Application["MyKey"] == null)
{
Application["MyKey"] = 0;
}

int value = (int)Application["MyKey"] + 1;
Application["MyKey"] = value;
return value;
}

Subsequent calls from my client to the above web method return values 1, 2, 3... as expected. (Note that the code is not thread safe but that's another story).

Regards
Sami

Nov 21 '05 #3

"RJ" <RJ@PostOnly.com> wrote in message
news:OT*************@TK2MSFTNGP11.phx.gbl...
Sami,
Thanks for performing the test. I have not enabled SessionState. I am
simply adding values to the Application object in the Application_Start
event handler method. Seconds later, I call other web methods in this web
service, which attempt to access the Application object by key ( Dim myVar
as String = Me.Application("Name") .... in VB.NET)
I immediately print out the value of myVar and it is never set. I am
assuming that Application_Start is called once before the first call to any web method? Is this approach sound, or should I add the values to the
Application object somewhere else in the web service code?


Yes, Application_Start is called once on the first request to a web
application.

I suggest you put in the test code in my previous post to see how it behaves
for you. If it works then the Application object is working the way it is
documented.

Some additional things I'd do to debug the problem:

- Make sure you access the Application object from same web application that
sets it (same virtual directory)
- Are you running a web farm? If so, then Application won't work.
- Put break points in event handlers in Global to trace a request. Check the
contents of Application on every break, or
- Add code to event handlers in Global to print out all the values in
Application:

foreach (string key in Application.Keys)
{
System.Diagnostics.Trace.WriteLine(string.Format(" key: {0} value: {1}",
key, Application[key]);
}

hth,
Sami
Nov 21 '05 #4

Sami-

I am having the same problem, my wp recycles after every call and
cannot figure out how to stop it from happening. I implemented you
code and have a client that makes the consecutive calls. Each respons
is 1, and the Application_Start and Application_End calls are made fo
every call. Any ideas?

Sami Vaaraniemi wrote:
*"RJ" <RJ@PostOnly.com> wrote in message
news:uB**************@tk2msftngp13.phx.gbl...
I tried using the Application object to store data in som

variables,
which
would be globally accessible within the web service applicatio

code. On
subsequent web method calls, the Application object no longe

contains the
variables I added. Is the Application object supposed to work th

way it
does in a web page?

I was just attempting to read the web.config file once at startup.

Now I
am
just reading the web.config file in every web method, on every cal

to the
web service. Should I have to do this? Thanks for any insights.

RJ


The Application object should work the same way it works in an
ASP.NET
application: the values stored in it are remembered from request t
request.
The Application object loses the values when the applicatio
restarts. Are
you sure the application is not restarting between calls for som
reason?
Btw there is no need for you to enable SessionState in order to us
the
Application object.

I did a small test with this web method:

[WebMethod]
public int TestApplicationState()
{
if (Application["MyKey"] == null)
{
Application["MyKey"] = 0;
}

int value = (int)Application["MyKey"] + 1;
Application["MyKey"] = value;
return value;
}

Subsequent calls from my client to the above web method return value
1, 2,
3... as expected. (Note that the code is not thread safe but that'
another
story).

Regards
Sami

-
jackstraw1
-----------------------------------------------------------------------
Posted via http://www.mcse.m
-----------------------------------------------------------------------
View this thread: http://www.mcse.ms/message946710.htm

Nov 21 '05 #5

"jackstraw10" <ja****************@mail.mcse.ms> wrote in message
news:ja****************@mail.mcse.ms...

Sami-

I am having the same problem, my wp recycles after every call and I
cannot figure out how to stop it from happening. I implemented your
code and have a client that makes the consecutive calls. Each response
is 1, and the Application_Start and Application_End calls are made for
every call. Any ideas?


That's pretty odd. Is there anything in the event log that would give a hint
as to why the app is shutting down? Look at error messages and messages
where the source is W3SVC.

Regards,
Sami
Nov 21 '05 #6

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

Similar topics

18
526
by: jabailo | last post by:
I wrote a program that loops through a file of records. It parses each line in the file and sends them to a web service that inserts them into an AS400DB2 database using Asynch calls. This is...
9
4146
by: Clint | last post by:
Hey all - Excuse the cross-post ... I'm not sure what the appropriate newsgroup would be for this question. I have a question that I'm not quite sure how to ask. For all I know, I have the...
3
2645
by: Marc Gravell | last post by:
Kind of an open question on best-practice for smart-client design. I'd really appreciate anyones views (preferably with reasoning, but I'll take what I get...). Or if anybody has any useful links...
0
864
by: Michael | last post by:
Hi all, I have a Web app that calls a Web service to get back some data that very rarely change, like a lookup table to populate a dropdown. I'm wondering how best to cache that data. Can...
2
2070
by: Jonathan Woods | last post by:
Hi there, I have encountered problem of losing data sending over internet using web service. I consume web service that connected Oracle Database. I submit 687 SOAP Messages to 1 Web Method...
5
11868
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
0
1018
by: David++ | last post by:
Hello, I'm looking for a tool which will allow me to monitor Web Service calls. I'm just testing in VS2005 at the moment and running the web services locally using the default VS2005 server. I...
1
2434
by: nileshm | last post by:
I am working on PDA application which calls web service that fetches 40 customer details in one call. The call from PDA over GPRS takes between 4-6 minutes to fetch the data. 4 out of 5 calls fail....
2
1844
by: s4lin | last post by:
problem is pagination not retaining data field i have form with general data field, and i need to select some option which is store in database, so i open another page with retrieving data from...
0
7212
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
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
7364
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...
1
7017
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
7470
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
5604
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,...
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.