Got this question yesterday; can the ASP.NET session object be used to store state in a web service? The answer is yes, but the web service method must be marked with EnableSession = true.
Below is a small code snippet that shows how it's done:
[WebMethod(EnableSession = true)]public string HelloWorld(){ // Check if item in cache, else add it. if (HttpContext.Current.Session["stateItem"] == null) { HttpContext.Current.Session["stateItem"] = "some-item-to-store"; } return (string)HttpContext.Current.Session["stateItem"];}
Simple, but yet easy to forget...
Remember Me
a@href@title, strike
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.