-
ASP.NET creates Web services and manages Web service status
2009-Thursday-21
XML Web Services When implementing XML Web services derived from the WebService class, you can use the same state management options as other ASP.NET applications. The WebService category contains many public ASP.NET objects, including Session and Application objects.
The Application object provides a mechanism for storing data that is accessible to code running in a Web application, while the Session object allows data to be stored on a per-client session basis. If the client supports cookies, cookies can be used to identify client conversations.
The data stored in the Session object is only available when the EnableSession property of the WebMethod property is set to true to use WebService-derived classes. Application objects are automatically accessible to WebService derived species.
Declaring an XML Web service to access and retain specific state of a specific client session
[C#]
<%@ WebService Language="C#" Class="ServerUsage" %>
[Visual Basic]
<%@ WebService Language="VB" Class="ServerUsage" %>
Add a reference to the System.Web.Services namespace.
[C#]
using System.Web.Services;
[Visual Basic]
Imports System.Web.Services
A type that implements XML Web services derived from the WebService type.
[C#]
public class ServerUsage : WebService
[Visual Basic]
Public Class ServerUsage : Inherits WebService
Declare an XML Web service procedure 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
Archive a status In a conversation, give the status a name so it can be easily retrieved later. In the following demonstration, the value one is retained in a state variable named MyServiceUsage.
[C#]
Session["MyServiceUsage"] = one;
[Visual Basic]
Session("MyServiceUsage") = One access to the state variables sealed in the Session.
In the following demonstration, the MyServiceUsage state variable is accessed to increment its value
[C#]
Session["MyServiceUsage"] = ((int) Session["MyServiceUsage"]) + one;
[Visual Basic]
Session("MyServiceUsage") = CInt(Session("MyServiceUsage")) + one that accesses and retains the specific state of an XML Web service in a Web application
Declaration of an XML Web service
[C#]
<%@ WebService Language="C#" Class="ServerUsage" %>
[Visual Basic]
<%@ WebService Language="VB" Class="ServerUsage" %>
Add an excerpt to the System.Web.Services namespace
[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
Declaring an XML Web service procedure
[C#]
[WebMethod]
public int PerSessionServiceUsage()
[Visual Basic]
<WebMethod>_
Public Function PerSessionServiceUsage() As Integer
Archiving the state In the Application, assign a name to the state so that it can be easily retrieved later. In the following demonstration, the value one is retained in a state variable named appMyServiceUsage.
[C#]
Application["appMyServiceUsage"] = one;
[Visual Basic]
Application("appMyServiceUsage") = Access the state variables stored in Application.
In the following demonstration, the appMyServiceUsage state variable is accessed
Welcome to the .NET community forum and interact with 2 million technical staff >> Enter
to increment its value.
[C#]
Application["appMyServiceUsage"] =
((int) Application["appMyServiceUsage"]) + one;
[Visual Basic]
Application("appMyServiceUsage") = _
CInt(Application("appMyServiceUsage")) + a source of this article:
My abnormal network
JavaException
DotnetException
Oracle