Getting sessions to ASMX webservice
-
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.
-
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.
-
Well, See this msdn[^] article about sharing your session state between asp.net and web services.
Yusuf May I help you?
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