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

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

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
主站蜘蛛池模板: 轮台县| 肇东市| 镇雄县| 定安县| 工布江达县| 莱州市| 娄底市| 祁阳县| 威宁| 榆林市| 水富县| 江源县| 吴桥县| 陇西县| 永城市| 通道| 柳江县| 蒙城县| 西昌市| 台州市| 姚安县| 安康市| 大方县| 石楼县| 宁都县| 襄城县| 阳春市| 明溪县| 睢宁县| 江西省| 临猗县| 七台河市| 喀喇| 二连浩特市| 伊川县| 临沭县| 安徽省| 柞水县| 武城县| 岐山县| 杭锦旗|