[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 |