title: Create wcf web service with instanceContextMode = PerSession
body: <p>I have a very simple service:</p>
  
  <pre><code>[ServiceContract]    
  public interface IPncService
  {
      [System.ServiceModel.Web.WebGet(UriTemplate = "set/{val}")]
      [OperationContract]
      bool SetVariable(string val);
  
      [System.ServiceModel.Web.WebGet(UriTemplate = "get")]
      [OperationContract]
      string GetVariableVal();
  }
  
  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
  public class PncService : IPncService
  {
      string someVariable;
  
      public bool SetVariable(string val)
      {
          if (string.IsNullOrWhiteSpace(val))
              return false;
          else
          {
              someVariable = val;
              return true;
          }            
      }
  
      public string GetVariableVal() {
          return someVariable;
      }
  }
  </code></pre>
  
  <p>Why does the variable <code>someVariable</code> does not retain its value per session? </p>
  
  <p>In other words if I do:</p>
  
  <p><img src="https://i.stack.imgur.com/R55zj.png" alt="enter image description here"></p>
  
  <p><strong>and then go to:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/bwJgx.png" alt="enter image description here"></p>
  
  <p>Why is the value of <code>someVariable = null</code> ? Is it a different session? I call that method on the same browser right after calling the set method...</p>