473,624 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Test if session is set on web service

Hello
I am hoping someone knows the answers I seek..

I am writing code in a C# web service solution.
I want to create an instance of an object (that I created) in a
Session variable. I need to check to see if the Session variable has
been set yet. If the variable already contains an instance of this
object then I will retrieve and use the existing object, rather than
create a new instance. ie. I will only create a new object the first
time the procedure is called, and then save it for the next time.

So, in an article I found in my MSDN help entitled
"Code: Reading Values From Session State (Visual C#)"
the procedure recommended to check to see if the Session var was set
yet, is this:
if (Session["SomeVarNam e"] == null)

When I do this, I get the
"Object reference not set to an instance of an object" error.
Checking in debug, pointing to the word Session, the following
information pops up:
Session = <undefined value>

I thought Session was supposed to be created first thing when a page
is accessed. So, how come mine is not defined yet?

Could it be because it is an .asmx file rather than an aspx file?

If asmx pages don't create a Session object, is there a way to
maintain session information in a web service?

Thanks much
Jeff
Nov 19 '05 #1
4 1886
http://msdn.microsoft.com/library/de...ce08062002.asp

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Jeff User" <je*******@hotm ail.com> wrote in message
news:0b******** *************** *********@4ax.c om...
Hello
I am hoping someone knows the answers I seek..

I am writing code in a C# web service solution.
I want to create an instance of an object (that I created) in a
Session variable. I need to check to see if the Session variable has
been set yet. If the variable already contains an instance of this
object then I will retrieve and use the existing object, rather than
create a new instance. ie. I will only create a new object the first
time the procedure is called, and then save it for the next time.

So, in an article I found in my MSDN help entitled
"Code: Reading Values From Session State (Visual C#)"
the procedure recommended to check to see if the Session var was set
yet, is this:
if (Session["SomeVarNam e"] == null)

When I do this, I get the
"Object reference not set to an instance of an object" error.
Checking in debug, pointing to the word Session, the following
information pops up:
Session = <undefined value>

I thought Session was supposed to be created first thing when a page
is accessed. So, how come mine is not defined yet?

Could it be because it is an .asmx file rather than an aspx file?

If asmx pages don't create a Session object, is there a way to
maintain session information in a web service?

Thanks much
Jeff

Nov 19 '05 #2

John
Thanks for the info. I have read this article, but it still has not
solved the problem, entirely. I added (EnableSession= true) to my
WebMethod attribute as shown:

[WebMethod(Enabl eSession=true)]

And, as stated in the article, hitting this service url from the
browser, getting the test page and testing it, works. Every time I
retest, the counter (good example code from article) increases.

However, the article does not address my case in which my client IS a
browser. My client app is a web page created in VS using the "Add Web
Refernce" tool. When my client hits the webService, it is treated as a
new session every time.

So, I added the cookieContainer code anyway, just to try it.
This yields a compile error :
c:\inetpub\wwwr oot\TestClient\ WebForm1.aspx.c s(118):
'TestClient.loc alhost.Service1 ' does not contain a definition for
'cookieContaine r'

Service1 being the web service .

I am coding in C#, I think the example was VB, however I don't know
that that matters here.
Anyway, any other ideas?

Really stuck
Thanks again
Jeff

On Mon, 7 Nov 2005 21:17:03 -0000, "John Timney \( MVP \)"
<ti*****@despam med.com> wrote:
http://msdn.microsoft.com/library/de...ce08062002.asp


Nov 19 '05 #3
Greetings all
In addition to the article that John Timney suggested:
http://msdn.microsoft.com/library/de...ce08062002.asp

I would also recommend this article:
http://support.microsoft.com/default...b;en-us;816637

The first article got me 3/4 of the way there.
The 2nd article listed here includes saving the cookie on the client
side for use on the next call to the server.

Thanks again John for giving me the good start that I needed.

Jeff
On Mon, 07 Nov 2005 21:07:43 GMT, Jeff User <je*******@hotm ail.com>
wrote:
Hello
I am hoping someone knows the answers I seek..

I am writing code in a C# web service solution.
I want to create an instance of an object (that I created) in a
Session variable. I need to check to see if the Session variable has
been set yet. If the variable already contains an instance of this
object then I will retrieve and use the existing object, rather than
create a new instance. ie. I will only create a new object the first
time the procedure is called, and then save it for the next time.

So, in an article I found in my MSDN help entitled
"Code: Reading Values From Session State (Visual C#)"
the procedure recommended to check to see if the Session var was set
yet, is this:
if (Session["SomeVarNam e"] == null)

When I do this, I get the
"Object reference not set to an instance of an object" error.
Checking in debug, pointing to the word Session, the following
information pops up:
Session = <undefined value>

I thought Session was supposed to be created first thing when a page
is accessed. So, how come mine is not defined yet?

Could it be because it is an .asmx file rather than an aspx file?

If asmx pages don't create a Session object, is there a way to
maintain session information in a web service?

Thanks much
Jeff


Nov 19 '05 #4
not that I did much, but your welcome all the same :)

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Jeff User" <je*******@hotm ail.com> wrote in message
news:t9******** *************** *********@4ax.c om...
Greetings all
In addition to the article that John Timney suggested:
http://msdn.microsoft.com/library/de...ce08062002.asp

I would also recommend this article:
http://support.microsoft.com/default...b;en-us;816637

The first article got me 3/4 of the way there.
The 2nd article listed here includes saving the cookie on the client
side for use on the next call to the server.

Thanks again John for giving me the good start that I needed.

Jeff
On Mon, 07 Nov 2005 21:07:43 GMT, Jeff User <je*******@hotm ail.com>
wrote:
Hello
I am hoping someone knows the answers I seek..

I am writing code in a C# web service solution.
I want to create an instance of an object (that I created) in a
Session variable. I need to check to see if the Session variable has
been set yet. If the variable already contains an instance of this
object then I will retrieve and use the existing object, rather than
create a new instance. ie. I will only create a new object the first
time the procedure is called, and then save it for the next time.

So, in an article I found in my MSDN help entitled
"Code: Reading Values From Session State (Visual C#)"
the procedure recommended to check to see if the Session var was set
yet, is this:
if (Session["SomeVarNam e"] == null)

When I do this, I get the
"Object reference not set to an instance of an object" error.
Checking in debug, pointing to the word Session, the following
information pops up:
Session = <undefined value>

I thought Session was supposed to be created first thing when a page
is accessed. So, how come mine is not defined yet?

Could it be because it is an .asmx file rather than an aspx file?

If asmx pages don't create a Session object, is there a way to
maintain session information in a web service?

Thanks much
Jeff

Nov 19 '05 #5

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

Similar topics

0
513
by: Carson Saunders | last post by:
I have a C# client application that calls a web service. I implement the CookieContainer class on the client to ensure the session is kept. However, I'm having trouble with the session timeout. I have set the timeout to be one minute and have done this in IIS, in web.config, and in global.asax. My problem/question relates to the re-use of the session ID. When I start my client app, I retrieve the session ID from the web service by...
3
1670
by: Jeff User | last post by:
Hello I am hoping someone knows the answers I seek.. I am writing code in a C# web service solution. I want to create an instance of an object (that I created) in a Session variable. I need to check to see if the Session variable has been set yet. If the variable already contains an instance of this object then I will retrieve and use the existing object, rather than create a new instance. ie. I will only create a new object the first...
2
3141
by: Jeff User | last post by:
Greetings I am writing code in a C# web service solution. I want to create an instance of an object (that I created) in a Session variable. I need to check to see if the Session variable has been set yet. If the variable already contains an instance of this object then I will retrieve and use the existing object, rather than create a new instance. ie. I will only create a new object the first time the procedure is called, and then save...
3
6020
by: Nhi Lam | last post by:
Hi, I understand that there are 3 modes in which I can configure the SessionStateModule. What I need is an out of process Session State store with fail over support. The "SQL Server Mode" seems to be it, but I heard there is quite a bit of degradation in performance for using this mode. My next option is the "State Server Mode". However, this mode does not give me the fail over support. Is there anything that I can do the enhance the...
3
3441
by: Mark | last post by:
Ok, I know that .net inherently does not share session data across asp.net projects, but is there any decent work around to this. We already have a big chunk of our application using the asp.net session object (using state service). I'd like to start breaking out our functionality into component projects, but I'd like to get this session issue worked out first. Any ideas?? I found this article , but it sounds like kind of a pain.
1
1247
by: giatorta | last post by:
Hi all, I have a scenario where the client calls Web Service WS1 and WS1 calls Web Service WS2 I have methods M1 on WS1 and M2 on WS2 both with EnabledSession=True assume M1 on WS1 does the following (in VB-like pseudocode): If (new session) Then Session("foo1") = "OLD1"
4
4122
by: pgmanno | last post by:
Hello all, Here is my question. I have an AxWebBrowser (hereafter refered to as "Browser") control framed in a smart client. The smart client requires logon, and the web app that the Browser is pointing to requires logon and is using Forms Authentication. I have set up a web service so that when the user logs on to the smart client, s/he can also log on to the website (basically, the username/password is passed up, auth ticket set...
11
7903
by: Joseph Geretz | last post by:
I've been looking at two approaches for the maintenance of Session state for a Web Service application. One approach uses the old familiar Session object which I've used in the past for Web applications. As far as I can see, the Session approach is non-standard since Web Services are supposed to be agnostic with respect to their clients. It seems that cookies are outside the Web Service standard; therefore, such a Web Service application...
5
5888
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
Hi All, I am using asp.net session state service to store session. The concurrent online user will be almost 2000. Could asp.net session state service afford this? Is there any limitation about asp.net session state service? -Billy
0
8236
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8173
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8679
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8621
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7159
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1482
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.