Web Service 的状态控制

来源:互联网 发布:hiclass软件 编辑:程序博客网 时间:2024/06/06 17:32

    在WEB SERVICE 中可以使用在WEB FORM中经常用的两个非常有用的状态管理对象Application和Session .

例如:

using System;
using System.Web.Services;

public class myService:WebService
{
 [WebMethod(EnableSession=true)]
 public String SessionMethod()
 {
  if(Session["aa"]==null)
  {
   Session["aa"]=1;
  }
  else
  {
   Session["aa"]=((int)Session["aa"])+1;

  }

  return "returnString";
 }


 [WebMethod(EnableSession=true)]
 public String ApplicationMethod()
 {
  if (Application["bb"]==null)
  {
   Application["bb"]=1;
  }
  else
  {
   Application["bb"]=((int)Application["bb"])+1;
  }
  return "returnString";
 }