:: thoughts on team system and more RSS 2.0
# Friday, 22 December 2006

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...

Friday, 22 December 2006 20:36:30 (W. Europe Standard Time, UTC+01:00)  #    -
Web Services
News
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2018
Mathias Olausson
Sign In
Statistics
Total Posts: 100
This Year: 0
This Month: 0
This Week: 0
Comments: 65
All Content © 2018, Mathias Olausson
DasBlog theme 'Business' created by Christoph De Baene (delarou)