Webservice and session

Discussion in 'ASP .Net Web Services' started by Morten V. Pedersen, May 10, 2006.

  1. Hello

    I have a web-service with a web-method where sessionstate=false.
    The web method calls a method in another assembly.

    Also I have a web-method where sessionstate=true which calls the same method
    in the other assembly.

    Here I can always access HttpContext.Current, but how do I determine if I
    can access HttpContext.Current.Session?

    It's in 1.1 framework.

    /Morten
    Morten V. Pedersen, May 10, 2006
    #1
    1. Advertising

  2. Hi Morten,

    Thank you for posting.

    As for the SessionState setting for ASP.NET webservice, it is a webmethod
    level setting (through the WebMethodAttribute), so there is not directly
    property for us to check this in the webservice class. However, if you do
    want to check certain WebMethod's SessionState setting, you can consider
    using the Reflection api to query the "WebMethodAttribute" attribute. For
    example:

    ===============
    MethodInfo mi = this.GetType().GetMethod("HelloWorld",
    System.Reflection.BindingFlags.Instance |
    System.Reflection.BindingFlags.Public);


    object[] objs = mi.GetCustomAttributes(typeof(WebMethodAttribute),
    true);


    if (objs != null && objs.Length >0)
    {
    WebMethodAttribute wsa = (WebMethodAttribute)objs[0];

    if (wsa != null)
    {
    return "Session: " + wsa.EnableSession;
    }
    }
    ============================

    BTW, generally, it is not recommended that we use SessionState or other
    stateful storage in Webservice since they're platform dependent.

    Hope this helps.



    Regards,

    Steven Cheng
    Microsoft Online Community Support


    ==================================================

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], May 11, 2006
    #2
    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. Jeff Smythe
    Replies:
    3
    Views:
    1,238
    Jeff Smythe
    Jan 2, 2004
  2. batista
    Replies:
    1
    Views:
    909
    Laurent Bugnion
    Jan 26, 2006
  3. batista
    Replies:
    0
    Views:
    561
    batista
    Jan 26, 2006
  4. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    5,267
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
  5. Jazzis
    Replies:
    2
    Views:
    242
    Jazzis
    Sep 23, 2003
Loading...

Share This Page