设为首页
加入收藏
繁體中文
首 页客家风情客家影音山歌在线客家商城聊天室留言墙测字算命下载中心IT 技术客家论坛
您当前的位置:天南地北客家人 -> IT 技术-> NET专区 -> 正文 退出登录 用户管理
栏目导航
· ASP · JSP
· 网络安全 · NET专区
· XML专区 · PHP专区
热门文章
· ASP+JavaScript的完整的..
· [图文] 防范非法用户的侵..
· ASP从数据库中获取文件..
· 网络管理中的常用命令
· [图文] FSO组件操作实例..
· [图文] 千年虫二世诞生业..
· 网络常见木马的手工清除..
· [图文] 简单购物车教程
· 一个ASP(VBScript)简..
· 利用ASP远程获取内容
· 网络常见木马的手工清除..
· asp常用数据库连接方法..
相关文章
· ASP.NET创建XML Web服务..
· ASP.NET创建XML Web服务..
· ASP.NET创建XML Web服务..
· asp.net高级教程(一)-..
· asp.net高级教程(二)-..
· asp.net高级教程(三)-..
· asp.net高级教程(四)-..
· [图文] asp.net高级教程(..
· ASP.NET 打造互联网未来..
· ASP.NET 打造互联网未来..
· ASP.NET 打造互联网未来..
· ASP.NET 打造互联网未来..
· Asp.net+Xml开发网络硬盘..
· ASP.NET中树形图的实现
· ASP.NET中Cookie编程的基..
ASP.NET创建XML Web服务全接触(12)
作者:风未起时  来源:中国站长学院  发布时间:2008-4-16 11:39:25  发布人:Admin

减小字体 增大字体

管理Web服务状态(2)

    

  在下面示例中,appMyServiceUsage状态变量被访问来递增其值。下面的代码示例是一个使用两个XML Web服务方法的XML Web服务:ServerUsage和PerSessionServerUage。ServerUsage是一个点击计数器,用于访问ServerUsage XML Web服务方法时计数,而不管客户端如何与XML Web服务方法通信。例如,如果三个客户端连续地调用ServerUsage XML Web服务方法,最后一个接收一个返回值3。而PerSessionServiceUsage则是用于一个特别的客户端会话的计数器。如果三个客户端连续地访问PerSessionServiceUsage,每个客户端都会在第一次调用的时候接收到相同的结果。

[C#]
<%@ WebService Language="C#" Class="ServerUsage" %>
using System.Web.Services;

public class ServerUsage : WebService {
 [ WebMethod(Description="Number of times this service has been accessed.") ]
 public int ServiceUsage() {
  // If the XML Web service method hasn't been accessed,
  // initialize it to 1.
  if (Application["appMyServiceUsage"] == null)
  {
   Application["appMyServiceUsage"] = 1;
  }
  else
  {
   // Increment the usage count.
   Application["appMyServiceUsage"] = ((int) Application["appMyServiceUsage"]) + 1;
  }
  return (int) Application["appMyServiceUsage"];
 }

 [ WebMethod(Description="Number of times a particualr client session has accessed this XML Web service method.",EnableSession=true) ]
 public int PerSessionServiceUsage() {
  // If the XML Web service method hasn't been accessed, initialize
  // it to 1.
  if (Session["MyServiceUsage"] == null)
  {
   Session["MyServiceUsage"] = 1;
  }
  else
  {
   // Increment the usage count.
   Session["MyServiceUsage"] = ((int) Session["MyServiceUsage"]) + 1;
  }
  return (int) Session["MyServiceUsage"];
 }
}

[Visual Basic]
<%@ WebService Language="VB" Class="ServerUsage" %>
Imports System.Web.Services

Public Class ServerUsage
Inherits WebService

<WebMethod(Description := "Number of times this service has been accessed.")> _
Public Function ServiceUsage() As Integer
' If the XML Web service method hasn't been accessed, initialize
' it to 1.
If Application("appMyServiceUsage") Is Nothing Then
 Application("appMyServiceUsage") = 1
Else
 ' Increment the usage count.
 Application("appMyServiceUsage") = _
 CInt(Application("appMyServiceUsage")) + 1
End If
Return CInt(Application("appMyServiceUsage"))
End Function

<WebMethod(Description := "Number of times a particular client session has accessed this XML Web service method.", EnableSession := True)> _
Public Function PerSessionServiceUsage() As Integer
' If the XML Web service method hasn't been accessed,
' initialize it to 1.
If Session("MyServiceUsage") Is Nothing Then
 Session("MyServiceUsage") = 1
Else
 ' Increment the usage count.
 Session("MyServiceUsage") = CInt(Session("MyServiceUsage")) + 1
End If
 Return CInt(Session("MyServiceUsage"))
End Function

End Class


[] [返回上一页] [打 印] [收 藏]
下一篇文章:已经没有了
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论…]
关于本站 - 网站合作 - 免责声明 - 友情连接 - 网站地图 - 客家论坛
本站部份内容来自网络 如无意中侵犯了您的权利 请及时与我们联系 我们会尽快处理
Copyright © 2006-2012   天南地北客家人
Email:hakka360@sina.com   客家人QQ群:33754730
粤ICP备07019796号