人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

ASP.NET創建XML Web服務全接觸(12)

ASP.NET創建XML Web服務全接觸(12)

更新時間:2022-09-02 文章作者:未知 信息來源:網絡 閱讀次數:

管理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


溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 耒阳市| 铁岭县| 报价| 白沙| 尼木县| 民和| 辛集市| 景宁| 梅河口市| 葫芦岛市| 昔阳县| 藁城市| 日土县| 周宁县| 兴隆县| 江油市| 扎鲁特旗| 扎囊县| 友谊县| 高台县| 田东县| 马边| 同心县| 东丰县| 金溪县| 思南县| 拉孜县| 大荔县| 永清县| 乌兰县| 乌拉特后旗| 棋牌| 鄂伦春自治旗| 丹棱县| 郓城县| 定南县| 蓝田县| 南丰县| 托克托县| 安多县| 庆安县|