Click to See Complete Forum and Search --> : Problem accessing Session in webservice through client application


mastertoto
August 7th, 2003, 12:00 PM
I have a web service accessed by an application that needs to keep session information, like the username,etc.

I've used Session["Username"]=somename; to set the session variable. This works perfectly when accessed through a web browser. When I try to access it from a client application, this fails, the variable doesn't exist.

Since the webservice gets automatically instantiated at every call, I end up with a different SessionID, which explains why the program crashes, the variable doesn't exist in the new session.

I've tried using Application["Username"] , this works but i need the variable to be per-user, hence the use of Session.

EnableSession=true is set in the webservice.

If anybody has a solution to this problem, please let me know

kaneda
September 16th, 2003, 12:39 PM
hi,

your client has to set a cookieContainer where you instantiate your webService reference :)

example:

myWebServ = new WebServ.WSRef();
myWebServ.Credentials = System.Net.CredentialCache.DefaultCredentials;

if(emWebService_.CookieContainer == null)
{
emWebService_.CookieContainer = new CookieContainer();
}

end example:

the cookie container sees to it that your client gets the correct session

p.s.

this uses the package System.Net