Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Getting sessions to ASMX webservice

Getting sessions to ASMX webservice

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netwindows-adminquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matt Cavanagh
    wrote on last edited by
    #1

    I have an ASMX webservice hosted alongside my ASP.NET web app. It is in the same project, hosted as the same IIS web application, and compiles to the same DLL. Now, I need to get the users session into the Webservice. To test this I made this simple method:

    [WebMethod(EnableSession = true)]
    public string checkSession()
    {
    return HttpContext.Current.Session["userid"].ToString();
    }

    So, first I login to my web app, then in the browser goto my webservice and click "checkSession" on that auto generated test page. I have tested this on 3 computers. All 3 of those work fine with the webapp(so the sessions are being created etc), and 2 of those return the value of Session["userid"] on invoking the webmethod, however the last computer returns "Object reference not set to an instance of an object" because Session is null. So, whats the difference between these computers and why can my ASP.NET app get the sessions on all computers but the webservice cant? I have also tested with my cellphone and it works there too. Thanks:)

    Strive to be humble enough to take advice, and confident enough to do something about it.

    Y 1 Reply Last reply
    0
    • M Matt Cavanagh

      I have an ASMX webservice hosted alongside my ASP.NET web app. It is in the same project, hosted as the same IIS web application, and compiles to the same DLL. Now, I need to get the users session into the Webservice. To test this I made this simple method:

      [WebMethod(EnableSession = true)]
      public string checkSession()
      {
      return HttpContext.Current.Session["userid"].ToString();
      }

      So, first I login to my web app, then in the browser goto my webservice and click "checkSession" on that auto generated test page. I have tested this on 3 computers. All 3 of those work fine with the webapp(so the sessions are being created etc), and 2 of those return the value of Session["userid"] on invoking the webmethod, however the last computer returns "Object reference not set to an instance of an object" because Session is null. So, whats the difference between these computers and why can my ASP.NET app get the sessions on all computers but the webservice cant? I have also tested with my cellphone and it works there too. Thanks:)

      Strive to be humble enough to take advice, and confident enough to do something about it.

      Y Offline
      Y Offline
      Yusuf
      wrote on last edited by
      #2

      Well, See this msdn[^] article about sharing your session state between asp.net and web services.

      Yusuf May I help you?

      M 1 Reply Last reply
      0
      • Y Yusuf

        Well, See this msdn[^] article about sharing your session state between asp.net and web services.

        Yusuf May I help you?

        M Offline
        M Offline
        Matt Cavanagh
        wrote on last edited by
        #3

        I have looked through that article, and have done everything up to the point about cookie containers. My webservice proxy has no such object, what am I missing? EDIT: Ok so I found that theres and attribute in the config file to enable the cookie container. But now my silverlight(which is what I am using to connect to the webservice) now gives this error: "CookieContainer is not supported when using a browser-based HTTP stack. Cookies will be automatically managed by the browser. To gain manual control over cookies, switch to a different HTTP stack, for example by using WebRequest.RegisterPrefix with WebRequestCreator.ClientHttp." But I don't think this has to do with Silverlight at all, or the cookiecontainer, because even that auto generated test page for the ASMX doesn't work.

        Strive to be humble enough to take advice, and confident enough to do something about it.

        modified on Wednesday, July 21, 2010 4:45 PM

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups