没有合适的资源?快使用搜索试试~ 我知道了~
在web服务中要用到ASP.NET中的会话对象,有2件事情需要做。 1.WebService 类需要继承System.Web.Services.WebService类 2.WebMethod中的EnableSession属性值应该设置为true 来看我们CalculatorWebService类,我们可以看到,它已经继承System.Web.Services.WebService类。但是,我们需要EnableSession属性值设置为true。 本文中,我们将试试在使用一个如下所示的GridView中的会话对象来展示最近的计算结果. 为了达成这个目的,首先要想下面这样,
资源推荐
资源详情
资源评论
ASP.NET如何使用如何使用web服务的会话状态服务的会话状态
在web服务中要用到ASP.NET中的会话对象,有2件事情需要做。
1.WebService 类需要继承System.Web.Services.WebService类
2.WebMethod中的EnableSession属性值应该设置为true
来看我们CalculatorWebService类,我们可以看到,它已经继承System.Web.Services.WebService类。但是,我们需要
EnableSession属性值设置为true。
本文中,我们将试试在使用一个如下所示的GridView中的会话对象来展示最近的计算结果.
为了达成这个目的,首先要想下面这样,修改CalculatorWebService类的Add方法.
[WebMethod(EnableSession = true)] public int Add(int firstNumber, int secondNumber)
{
List<string> calculations;
if (Session["CALCULATIONS"] == null)
{
calculations = new List<string>();
}
else
{
calculations = (List<string>)Session["CALCULATIONS"];
}
string strTransaction = firstNumber.ToString() + " + "
+ secondNumber.ToString()
+ " = " + (firstNumber + secondNumber).ToString();
calculations.Add(strTransaction);
Session["CALCULATIONS"] = calculations;
return firstNumber + secondNumber;
}
然后再引入另外一个公共方法来返回所有的计算结果. 要使用WebMethod特性来修饰这个方法,并且将EnableSession属
性设置为true.
[WebMethod(EnableSession = true)] public List<string> GetCalculations()
{
if (Session["CALCULATIONS"] == null)
{
List<string> calculations = new List<string>();
calculations.Add("You have not performed any calculations");
return calculations;
}
else
{
return (List<string>)Session["CALCULATIONS"];
}
资源评论
weixin_38654315
- 粉丝: 5
- 资源: 962
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功