I have a very simple service:
[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;
}
}
Why does the variable someVariable does not retain its value per session?
In other words if I do:

and then go to:

Why is the value of someVariable = null ? Is it a different session? I call that method on the same browser right after calling the set method…
You should have a read at this article : http://blogs.msdn.com/b/wenlong/archive/2010/02/21/using-asp-net-sessions-from-wcf.aspx
Short version :
Thus :