[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] public class Service1 : IService1 { //bool boolValue = true; //string stringValue = "Hello "; public string Greet(string words) { return GreetInternal(words); } public string Greet2(string words) { return GreetInternal(words); } string GreetInternal(string words) { MySessionState state = (MySessionState)HttpContext.Current.Session["MySessionState"]; if (state == null) { state = new MySessionState(); HttpContext.Current.Session["MySessionState"] = state; } int counter = state.Touch(); return string.Format("[Session '{0}'] You said: {1} (counter: {2})", HttpContext.Current.Session.SessionID, words, counter); } } class MySessionState { int counter; public MySessionState() { } public int Counter { get { return this.counter; } } public int Touch() { return Interlocked.Increment(ref this.counter); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)