ASP. NET create Web service management Web service status

Source: Internet
Author: User

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

 

Related Article

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.