Call dynamic webservice with session

Posted by  Jayden Bell
 1305  View(s)
Rate this:

I have webservice, provide to user. User must login to use it. My problem is when user login through WSLogin on webservice, I want to save session to check for a next time.

[WebMethod(EnableSession = true)]
public string WSLogin(string username, string password)
    // do something
    string sID = Guid.NewGuid().ToString();
    Session.Add("SID", sID); // save session
    return sID; // return to user to check next time
[WebMethod(EnableSession = true)]
public string CallSomethingService(string sID)
    string curSID = Session["SID"].ToString() // error, Object reference not set to an instance of an object.
    // do some thing

I call webservice dynamically. Thank for all help

  1. Re: Call dynamic webservice with session

    Hi Jayden, 

    Instead of this:

    Session.Add("SID", sID);

    use this:

    HttpContext.Current.Session["SID"] = sSid;