Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > How do I get session state

Reply
Thread Tools

How do I get session state

 
 
Donald Adams
Guest
Posts: n/a
 
      03-06-2007
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
 
 
 
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      03-06-2007
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
 
 
 
 
Donald Adams
Guest
Posts: n/a
 
      03-07-2007
Thanks that worked, but I was hoping I could use the session object in the
webservice constructor too.

,,,Donald

"Laurent Bugnion [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
 
John Saunders
Guest
Posts: n/a
 
      03-07-2007
"Donald Adams" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
 
Donald Adams
Guest
Posts: n/a
 
      03-08-2007
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 in message
news:(E-Mail Removed)...
> "Donald Adams" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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
 
John Saunders
Guest
Posts: n/a
 
      03-08-2007
"Donald Adams" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
 
Donald Adams
Guest
Posts: n/a
 
      03-09-2007
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 in message
news:(E-Mail Removed)...
> "Donald Adams" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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
 
John Saunders
Guest
Posts: n/a
 
      03-09-2007
"Donald Adams" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Unable to make the session state request to the session state server Maciek ASP .Net 0 09-15-2005 08:49 PM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM
Unable to make the session state request to the session state server Not Liking Dot Net Today ASP .Net 0 04-21-2004 11:54 AM
unable to make the session state request to the session state server shamanthakamani ASP .Net 1 11-20-2003 04:51 AM



Advertisments