HighTechTalks DotNet Forums  

How do I get session state

ASP.net Web Services microsoft.public.dotnet.framework.aspnet.webservices


Discuss How do I get session state in the ASP.net Web Services forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Donald Adams
 
Posts: n/a

Default How do I get session state - 03-06-2007 , 07:44 AM






How can I get session state for my user in a web service?

I understand that with WinForm clients that this was not necessary, but now
with Asp.net Ajax, I can access all the server objects but the session one.
I can use the User object but it's a lot of extra work.

Is Microsoft employees listening here?

Thanks in advance,
Donald Adams



Reply With Quote
  #2  
Old   
Laurent Bugnion [MVP]
 
Posts: n/a

Default Re: How do I get session state - 03-06-2007 , 05:15 PM






Hi,

Donald Adams wrote:
Quote:
How can I get session state for my user in a web service?

I understand that with WinForm clients that this was not necessary, but
now with Asp.net Ajax, I can access all the server objects but the
session one. I can use the User object but it's a lot of extra work.

Is Microsoft employees listening here?

Thanks in advance,
Donald Adams
You need to enable the Session state for your web service. By default,
they are stateless.

Use

[WebMethod( EnableSession=true )]

Also, see this:
http://geekswithblogs.net/lbugnion/a...25/107243.aspx
This is also true for web services.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch


Reply With Quote
  #3  
Old   
Donald Adams
 
Posts: n/a

Default Re: How do I get session state - 03-07-2007 , 07:53 AM



Thanks that worked, but I was hoping I could use the session object in the
webservice constructor too.

,,,Donald

"Laurent Bugnion [MVP]" <galasoft-lb (AT) bluewin (DOT) ch> wrote

Quote:
Hi,

Donald Adams wrote:
How can I get session state for my user in a web service?

I understand that with WinForm clients that this was not necessary, but
now with Asp.net Ajax, I can access all the server objects but the
session one. I can use the User object but it's a lot of extra work.

Is Microsoft employees listening here?

Thanks in advance,
Donald Adams

You need to enable the Session state for your web service. By default,
they are stateless.

Use

[WebMethod( EnableSession=true )]

Also, see this:
http://geekswithblogs.net/lbugnion/a...25/107243.aspx
This is also true for web services.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch


Reply With Quote
  #4  
Old   
John Saunders
 
Posts: n/a

Default Re: How do I get session state - 03-07-2007 , 10:35 AM



"Donald Adams" <BDA_2003 (AT) hotmail (DOT) com> wrote

Quote:
Thanks that worked, but I was hoping I could use the session object in the
webservice constructor too.
What prevents you from using it in the constructor?

John




Reply With Quote
  #5  
Old   
Donald Adams
 
Posts: n/a

Default Re: How do I get session state - 03-08-2007 , 08:22 AM



you mean
[WebMethod( EnableSession=true )]
can be used on the constructor too? I didn't think of the constructor as a
method that the client could call.
I thought there would be something that would apply to the whole class like:
[WebService( EnableSession=true )]
but that gives me an error.

,,,Donald Adams

"John Saunders" <john.saunders at trizetto.com> wrote

Quote:
"Donald Adams" <BDA_2003 (AT) hotmail (DOT) com> wrote in message
news:B382550F-6068-4FEC-BF76-0F9CED9EA64D (AT) microsoft (DOT) com...
Thanks that worked, but I was hoping I could use the session object in
the webservice constructor too.

What prevents you from using it in the constructor?

John



Reply With Quote
  #6  
Old   
John Saunders
 
Posts: n/a

Default Re: How do I get session state - 03-08-2007 , 01:24 PM



"Donald Adams" <BDA_2003 (AT) hotmail (DOT) com> wrote

Quote:
you mean
[WebMethod( EnableSession=true )]
can be used on the constructor too? I didn't think of the constructor as
a method that the client could call.
I thought there would be something that would apply to the whole class
like:
[WebService( EnableSession=true )]
but that gives me an error.
Ok, good point.

But what do you want to use Session for in the constructor? Were you aware
that the constructor will be called on every single web service call?

John




Reply With Quote
  #7  
Old   
Donald Adams
 
Posts: n/a

Default Re: How do I get session state - 03-09-2007 , 04:53 AM



John,

yes, I'm aware it will be called everytime, I want to initialize some values
that will be used in every web method.

Thanks for your help.
,,,Donald

"John Saunders" <john.saunders at trizetto.com> wrote

Quote:
"Donald Adams" <BDA_2003 (AT) hotmail (DOT) com> wrote in message
news:AAFE88DA-AEB9-4793-B81D-5EA0E9C4D7CE (AT) microsoft (DOT) com...
you mean
[WebMethod( EnableSession=true )]
can be used on the constructor too? I didn't think of the constructor as
a method that the client could call.
I thought there would be something that would apply to the whole class
like:
[WebService( EnableSession=true )]
but that gives me an error.

Ok, good point.

But what do you want to use Session for in the constructor? Were you aware
that the constructor will be called on every single web service call?

John



Reply With Quote
  #8  
Old   
John Saunders
 
Posts: n/a

Default Re: How do I get session state - 03-09-2007 , 07:05 AM



"Donald Adams" <BDA_2003 (AT) hotmail (DOT) com> wrote

Quote:
John,

yes, I'm aware it will be called everytime, I want to initialize some
values that will be used in every web method.
Donald,

What I mean is that I didn't see what use you would make of Session state
inside of the constructor. Do you mean that you want to use it to _read_
values from session state during the constructor, that you'd then use to
initialize values that will be used in every web method? I couldn't
understand a use case for _writing_ into session state during the
constructor call.

At any rate, you can simply place all of your session-specific
initialization code into a method which is called from each web method,
since session state will be available then.

John




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.