<%@ 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 Web service method hasn't been accessed,
// initialize it to 1.
<b> if (Application["appMyServiceUsage"] == null) </b>
{
<br /><b>Application["appMyServiceUsage"] = 1</b>;
}
else
{
// Increment the usage count.
<br /><b>Application["appMyServiceUsage"] = ((int) Application["appMyServiceUsage"]) + 1;</b>
}
return (int) <br /><b>Application["appMyServiceUsage"]</b>;
}
[ <br /><b>WebMethod</b>(Description="Number of times a particular client session has accessed this Web service method.",<br /><b>EnableSession=true</b>) ]
public int PerSessionServiceUsage() {
// If the Web service method hasn't been accessed, initialize
// it to 1.
<br /><b>if (Session["MyServiceUsage"] == null)</b>
{
<br /><b>Session["MyServiceUsage"] = 1;</b>
}
else
{
// Increment the usage count.
<br /><b> Session["MyServiceUsage"] = ((int) Session["MyServiceUsage"]) + 1;</b>
}
return (int) <br /><b>Session["MyServiceUsage"];</b>
}
}
<%@ 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 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 Web service method.", EnableSession := True)> _
Public Function PerSessionServiceUsage() As Integer
' If the 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