Accessing Session from Web Service


Suppose you have an ASP.NET application, and you want to expose a web service from that same application. You want to call the webserivce in the same application from client side, and you need it to have access to the session data as your application.

You can either access the Session state from the Session object you get with your WebService base, or you can access it directly from the HttpContext. But if you use the Session Object in your web Method directly, it returns NULL and your WebMethod throws Object Reference Not Set Exception.

So In order to access the session state within a web method, first you must enable the session state for that method as

[WebMethod (EnableSession=true)]


Gopikrishna

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment