How do I get session state

Discussion in 'ASP .Net Web Services' started by Donald Adams, Mar 6, 2007.

  1. Donald Adams

    Donald Adams Guest

    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
    Donald Adams, Mar 6, 2007
    #1
    1. Advertising

  2. 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/archive/2007/02/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
    Laurent Bugnion [MVP], Mar 6, 2007
    #2
    1. Advertising

  3. Donald Adams

    Donald Adams Guest

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

    ,,,Donald

    "Laurent Bugnion [MVP]" <> wrote in message
    news:...
    > 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/archive/2007/02/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
    Donald Adams, Mar 7, 2007
    #3
  4. "Donald Adams" <> wrote in message
    news:...
    > 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
    John Saunders, Mar 7, 2007
    #4
  5. Donald Adams

    Donald Adams Guest

    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:...
    > "Donald Adams" <> wrote in message
    > news:...
    >> 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
    >
    >
    Donald Adams, Mar 8, 2007
    #5
  6. "Donald Adams" <> wrote in message
    news:...
    > 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
    John Saunders, Mar 8, 2007
    #6
  7. Donald Adams

    Donald Adams Guest

    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:...
    > "Donald Adams" <> wrote in message
    > news:...
    >> 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
    >
    >
    Donald Adams, Mar 9, 2007
    #7
  8. "Donald Adams" <> wrote in message
    news:...
    > 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
    John Saunders, Mar 9, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shamanthakamani
    Replies:
    1
    Views:
    3,482
    Natty Gur
    Nov 20, 2003
  2. Not Liking Dot Net Today
    Replies:
    0
    Views:
    600
    Not Liking Dot Net Today
    Apr 21, 2004
  3. Maciek
    Replies:
    0
    Views:
    8,237
    Maciek
    Sep 15, 2005
  4. jnickfl1
    Replies:
    0
    Views:
    579
    jnickfl1
    Sep 18, 2006
  5. Harry Haller
    Replies:
    0
    Views:
    1,648
    Harry Haller
    Nov 7, 2006
Loading...

Share This Page