title: How I can have a session id in wcf Service
body: <p>I'm coding an authentication service that have multiple methods.one of this method is ChangePassword. I want when any body wants to change the password, logon to system before.for this I want to have a session id and before changing pass check it.</p>
  
  <p>How I can do that and has this session time out?</p>
  
  <p><strong>EDIT 1)</strong></p>
  
  <p>I write this code but my session is null every time I want get it's value:</p>
  
  <p>Class:</p>
  
  <pre><code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
  public class Service2 : IService2
  {
      string result
      {   // Store result in AspNet session.
          get
          {
              if (HttpContext.Current.Session["Result"] != null)
                  return HttpContext.Current.Session["Result"].ToString();
              return "Session Is Null";
          }
          set
          {
              HttpContext.Current.Session["Result"] = value;
          }
      }
  
      public void SetSession(string Val)
      {
          result = Val;
      }
  
      public string GetSession()
      {
          return result;
      }
  </code></pre>
  
  <p>interface:</p>
  
  <pre><code>[ServiceContract(SessionMode = SessionMode.Required)]
  public interface IService2
  {
      [OperationContract]
      void SetSession(string Val);
  
      [OperationContract]
      string GetSession();
  }
  </code></pre>
  
  <p>web.config</p>
  
  <pre><code>  &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /&gt;
  </code></pre>
  
  <p><strong>EDIT 2)</strong>
  I wrote this code but it don't work:</p>
  
  <pre><code> private void button1_Click(object sender, EventArgs e)
      {
          MyService2.Service2Client srv = new MyService2.Service2Client();
          textBox1.Text = srv.GetSession();
  
      }
  
      private void button2_Click(object sender, EventArgs e)
      {
          MyService2.Service2Client srv = new MyService2.Service2Client();
          srv.SetSession(textBox1.Text);
          textBox1.Clear();
      }
  </code></pre>
  
  <p>every time I want to get Session value I get "Session Is Null" .Why?</p>