ASP. NET create XML Web Service full contact (12)

Source: Internet
Author: User

Manage Web service status (2)

In the following example, the appMyServiceUsage status variable is accessed to increase its value. The following code example shows an XML Web service that uses two XML Web Service Methods: ServerUsage and PerSessionServerUage. ServerUsage is a click counter used to access the ServerUsage XML Web Service method, regardless of how the client communicates with the XML Web Service method. For example, if three clients call the ServerUsage XML Web Service method consecutively, the last client receives a return value of 3. PerSessionServiceUsage is a counter used for a special client session. If the three clients continuously access PerSessionServiceUsage, each client receives the same result during the first call.

[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 hasnt 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 participant ualr client session has accessed this XML Web service method.", EnableSession = true)]
Public int PerSessionServiceUsage (){
// If the XML Web service method hasnt 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 hasnt 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 participant client session has accessed this XML Web service method.", EnableSession: = True)> _
Public Function PerSessionServiceUsage () As Integer
If the XML Web service method hasnt 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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.