:: thoughts on team system and more RSS 2.0
# Friday, December 22, 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, December 22, 2006 8:36:30 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0] -
Web Services
Navigation
Archive
<October 2008>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
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 2008
Mathias Olausson
Sign In
Statistics
Total Posts: 67
This Year: 15
This Month: 0
This Week: 0
Comments: 27
Themes
Pick a theme:
All Content © 2008, Mathias Olausson
DasBlog theme 'Business' created by Christoph De Baene (delarou)