Need help on setting and getting object from session in asp.net web services. I am saving session in one method of service and when try to retrieve it , just gives null. Sample code is bellow for saving session
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string setObj(NameValue[] formVars)
{
MyObject obj = new MyObject();
obj.vlaue = "1";
Session["obj"] = (object) obj;
return new JavaScriptSerializer().Serialize("");
}
For getting session :
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string getObj(NameValue[] formVars)
{
MyObject obj = new MyObject();
obj = (MyObject)Session["obj"] ;
return new JavaScriptSerializer().Serialize(obj.value);
}
In above code session data is null. I have also add session state in web config but won't work:
<system.web>
<pages>
<namespaces>
<add namespace="System.Web.SessionState"/>
</namespaces>
</pages>
<sessionState mode="InProc"></sessionState>
Thanks.