日期:2014-05-18  浏览次数:20818 次

关于web服务中使用Session的问题
web服务
[WebMethod(EnableSession = true)]
  public object SetSession()
  {
  Session["count"] = 0;
  return Session["count"];
  }
  [WebMethod(EnableSession = true)]
  public object AddSessionCount()
  {
  object obj = Session["count"];
  if (obj != null)
  {
  int i = Convert.ToInt32(obj);
  i++;
  Session["count"] = i;
  }
  return Session["count"];
  }
  [WebMethod(EnableSession = true)]
  public object GetSessionCount()
  {
  return Session["count"];
  }
调用:
localhost.WebService service = new localhost.WebService();
object obj=service.SetSession();
obj=service.AddSessionCount();
obj=service.AddSessionCount();
obj = service.GetSessionCount();
if (obj != null)
{
  Response.Write("service1:" + obj);
}
除了service.SetSession();返回0,其它的全反回null
难道我对他们所说的session的理解有误?

------解决方案--------------------
调用端需要一个对象保SESSION