首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于web服务中使用Session的有关问题

2012-04-19 
关于web服务中使用Session的问题web服务[WebMethod(EnableSession true)]public object SetSession(){Se

关于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

热点排行