ASP. NET create Web service management Web service status
When an XML Web service derived from a WebService class is implemented in a class, you can use the same status management options as other ASP. NET applications. The WebService class contains many common ASP. NET objects, including Session and Application objects.
The Application object provides a mechanism for storing data that can be accessed by code stored in Web applications, while the Session object allows data to be stored on the basis of each client Session. If the client supports cookies, you can use cookies to identify client sessions.
The data stored in the Session object is only available when the EnableSession attribute of the WebMethod attribute is set to true to use the class derived from WebService. A class derived from WebService can automatically access the Application object.
Access and save the specific status of a specific client session
Declare an XML Web service
[C #]
<% @ WebService Language = "C #" class = "ServerUsage" %>
[Visual Basic]
<% @ WebService Language = "VB" class = "ServerUsage" %>
Add a reference to the System. Web. Services domain name space.
[C #]
Using System. Web. Services;
[Visual Basic]
Imports System. Web. Services
Derived from the WebService class to implement the XML Web service class.
[C #]
Public class ServerUsage: WebService
[Visual Basic]
Public Class ServerUsage: Inherits WebService
Declare an XML Web service method and set the EnableSession attribute of the WebMethod attribute to true.
[C #]
[WebMethod (EnableSession = true)]
Public int PerSessionServiceUsage ()
[Visual Basic]
<WebMethod (EnableSession: = True)> _
Public Function PerSessionServiceUsage () As Integer
Save the status in the session and specify a name for the status for later retrieval. In the following example, value 1 is saved in a state variable named MyServiceUsage.
[C #]
Session ["MyServiceUsage"] = 1;
[Visual Basic]
Session ("MyServiceUsage") = 1
Access the status variables stored in the Session.
In the following example, the MyServiceUsage status variable is accessed to increase its value.
[C #]
Session ["MyServiceUsage"] = (int) Session ["MyServiceUsage"]) + 1;
[Visual Basic]
Session ("MyServiceUsage") = CInt (Session ("MyServiceUsage") + 1
Access and save the specific status of the XML Web service in the Web application
Declare an XML Web service
[C #]
<% @ WebService Language = "C #" class = "ServerUsage" %>
[Visual Basic]
<% @ WebService Language = "VB" class = "ServerUsage" %>
Add a reference to the System. Web. Services domain name space
[C #]
Using System. Web. Services;
[Visual Basic]
Imports System. Web. Services
Derived from the WebService class to implement the XML Web service class
[C #]
Public class ServerUsage: WebService
[Visual Basic]
Public Class ServerUsage: Inherits WebService
Declare an XML Web service method
[C #]
[WebMethod]
Public int PerSessionServiceUsage ()
[Visual Basic]
<WebMethod> _
Public Function PerSessionServiceUsage () As Integer
Save the status in Application and specify a name for the status for later retrieval. In the following example, value 1 is saved in a state variable named appMyServiceUsage.
[C #]
Application ["appMyServiceUsage"] = 1;
[Visual Basic]
Application ("appMyServiceUsage") = 1
Access the status variables stored in the Application.
In the following example, the appMyServiceUsage status variable is accessed.
Welcome to the. NET community forum and interact with 2 million technical staff> enter
To increase the value.
[C #]
Application ["appMyServiceUsage"] =
(Int) Application ["appMyServiceUsage"]) + 1;
[Visual Basic]
Application ("appMyServiceUsage") = _
CInt (Application ("appMyServiceUsage") + 1