title: Globally known variable for Web Service Application
body: <p>I need a globally known variable on a web service application.
  Since is web based, a globally declared variable's value remains the same when it is called again.</p>
  
  <p>I also tried to use Session on the web method but it is cleared when the other method is called.</p>
  
  <p>Here is a code sample.</p>
  
  <p>UI portion</p>
  
  <pre><code>private void btnOKLogIn_Click(object sender, EventArgs e)
  {
      CaprepWS caprepWS = new CaprepWS();
      caprepWS.setDatabase(Program.isProduction);
      string usrInfo = caprepWS.getUserInfo(tbUserName.Text.ToUpper().Trim());
  }
  </code></pre>
  
  <p>Web Service portion</p>
  
  <pre><code>[WebMethod(Description = "Database switcher", EnableSession = true)]
  public void setDatabase(bool isProduction)
  {
      Session["isProduction"] = isProduction;
  }
  
  [WebMethod(Description = "Get User Info", EnableSession = true)]
  public string getUserInfo(string username)
  {
      string wsResult = null;
      DataAccess sql = new DataAccess((bool)Session["isProduction"]);
  
      try
      {
          sql.OpenConn();
          wsResult = sql.Scalar(
                sql.spReader(sqlRoot + "spGetUserInfo.SQL")
              , username);
      }
      catch (Exception ex)
      {
          errorWritter(ex.Message);
          wsResult = null;
      }
      finally
      {
          sql.Dispose();
      }
  
      return wsResult;
  }
  </code></pre>
  
  <p>But even if I'm using the same instance on the UI, the session is not known (on the getUserInfo) on the other method and it is null.</p>
  
  <p>The thing is I am avoiding to put this variable on every web method as a parameter on my web service which is why I need it to be globally declared.</p>