Hi,
Since webservices are essentially statless you would need to pass a token
indentifying the user with every method call and using the Session object on
the webservice side. In normal windows applications this can be done by
setting CookieContainer property on the webservice proxy.
This unfortunatly is not supported in the .net compact framework as far as
I know so you cant use the session and you have to do things manually to
maintain state as follows:
1- Provide a method to generate a token id for the user.
2-Pass the id with every method call to the web service.
3-On the webservice side you can store the client data by using
the asp .net cache - System.Web.HttpContext.Current.Cache (warning this
cache isn't replicated so it won't work if you have a webfarm)
//just a quick code snippet webservice side//
//i'm storing a user string you could store any other object//
[WebMethod]
public string GetMyToken()
{
//just returning a unique id to identify the user usually this would be
done after authentication//
return System.Guid.NewGuid().ToString();
}
[WebMethod]
public void SaveMyStuff(string stuff,string token)
{
//save the user string in the asp.net cache//
System.Web.HttpContext.Current.Cache[token]=stuff;
}
[WebMethod]
public string GetMyStuff(string token)
{
//get the user string identified by the token//
return (string) System.Web.HttpContext.Current.Cache[token];
} code snippet webservice side//
Regards,
Rami Farhat
"Riga" wrote:
Hi guys,
I'm making a webservice that will be used by a pocketpc app. I want to be
able to keep an instance of some things (there are 2 collections and possibly
a database connection).
Is there a way to keep the state of the server? So that these collections
are not lost between method calls?