WebService WebService WebService WebService Class

定義

定義 XML Web Service 的選擇性 (Optional) 基底類別,這類別提供對通用 ASP.NET 物件 (例如應用程式和工作階段 (Session) 狀態) 的直接存取。Defines the optional base class for XML Web services, which provides direct access to common ASP.NET objects, such as application and session state.

public ref class WebService : System::ComponentModel::MarshalByValueComponent
public class WebService : System.ComponentModel.MarshalByValueComponent
type WebService = class
    inherit MarshalByValueComponent
Public Class WebService
Inherits MarshalByValueComponent
繼承
衍生

範例

下列範例會建立衍生自WebService的 XML Web Service, 以便Context使用屬性來取得伺服器上要求的時間。The example below creates an XML Web service, deriving from WebService, in order to use the Context property to obtain the time of the request on the server.

<%@ WebService Language="C#" Class="Util" %>
 
 using System;
 using System.Web.Services;
 
 public class Util: WebService {
   [ WebMethod(Description="Returns the time as stored on the Server",
   EnableSession=false)]
   public string Time() {
      return Context.Timestamp.TimeOfDay.ToString();
   }
 }
<%@ WebService Language="VB" Class="Util" %>
 
Imports System
Imports System.Web.Services

Public Class Util
    Inherits WebService
    
    <WebMethod(Description := "Returns the time as stored on the Server", _
        EnableSession := False)> _
    Public Function Time() As String
        
        Return Context.Timestamp.TimeOfDay.ToString()
    End Function
End Class

備註

如果您不需要存取通用 ASP.NET 物件, 您仍然可以建立 XML Web Service, 而不需衍生自WebServiceIf you don't need access to the common ASP.NET objects, you can still create an XML Web service without deriving from WebService. 您可以透過Context存取其他 ASP.NET 物件。Additional ASP.NET objects can be accessed through Context.

OneWay XML Web Service 具有SoapRpcMethodAttribute true HttpContext或的屬性設為的方法,就無法存取其。SoapDocumentMethodAttributeXML Web service methods that have the OneWay property of either SoapRpcMethodAttribute or SoapDocumentMethodAttribute set to true, do not have access to their HttpContext. 因此, 從該 XML Web Service 方法WebService null中存取類別的任何屬性, 會傳回。As such, accessing any of the properties of the WebService class, from within that XML Web service method, return null.

如果您使用 .NET Framework SoapRpcMethodAttribute版本 1.0 XML Web Service 已套用或SoapDocumentMethodAttribute屬性的方法, 且OneWay其屬性設定為true, 則無法使用來存取其HttpContext靜態Current屬性。If you are using the .NET Framework version 1.0 XML Web service methods that have either the SoapRpcMethodAttribute or SoapDocumentMethodAttribute attribute applied to them with the OneWay property of set to true, do not have access to their HttpContext using the static Current property. 若要存取HttpContext, 請從WebService衍生類別, 並存取Context屬性來執行 XML Web Service 方法。To access the HttpContext, derive the class implementing the XML Web service method from WebService and access the Context property.

建構函式

WebService() WebService() WebService() WebService()

初始化 WebService 類別的新執行個體。Initializes a new instance of the WebService class.

屬性

Application Application Application Application

取得目前 HTTP 要求的應用程式物件。Gets the application object for the current HTTP request.

Container Container Container Container

取得元件的容器。Gets the container for the component.

(Inherited from MarshalByValueComponent)
Context Context Context Context

取得目前要求的 ASP.NET HttpContext 將 HTTP 伺服器使用的所有 HTTP 特定內容封裝,以便處理 Web 要求。Gets the ASP.NET HttpContext for the current request, which encapsulates all HTTP-specific context used by the HTTP server to process Web requests.

DesignMode DesignMode DesignMode DesignMode

取得值,表示元件目前是否處於設計模式。Gets a value indicating whether the component is currently in design mode.

(Inherited from MarshalByValueComponent)
Events Events Events Events

取得附加在這個元件上的事件處理常式清單。Gets the list of event handlers that are attached to this component.

(Inherited from MarshalByValueComponent)
Server Server Server Server

取得目前要求的 HttpServerUtilityGets the HttpServerUtility for the current request.

Session Session Session Session

取得目前要求的 HttpSessionStateGets the HttpSessionState instance for the current request.

Site Site Site Site

取得或設定元件的站台。Gets or sets the site of the component.

(Inherited from MarshalByValueComponent)
SoapVersion SoapVersion SoapVersion SoapVersion

取得向 XML Web Service 提出 SOAP 要求時所使用的 SOAP 通訊協定版本。Gets the version of the SOAP protocol used to make the SOAP request to the XML Web service.

User User User User

取得 ASP.NET 伺服器 User 物件。Gets the ASP.NET server User object. 可用來驗證是否授權使用者執行要求。Can be used to authenticate whether a user is authorized to execute the request.

方法

Dispose() Dispose() Dispose() Dispose()

釋放 MarshalByValueComponent 所使用的所有資源。Releases all resources used by the MarshalByValueComponent.

(Inherited from MarshalByValueComponent)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放 MarshalByValueComponent 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the MarshalByValueComponent and optionally releases the managed resources.

(Inherited from MarshalByValueComponent)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

取得 IServiceProvider 的實作器。Gets the implementer of the IServiceProvider.

(Inherited from MarshalByValueComponent)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回任何包含 Component 名稱的 StringReturns a String containing the name of the Component, if any. 不應覆寫此方法。This method should not be overridden.

(Inherited from MarshalByValueComponent)

事件

Disposed Disposed Disposed Disposed

加入事件處理常式來接聽 (Listen) 元件上的 Disposed 事件。Adds an event handler to listen to the Disposed event on the component.

(Inherited from MarshalByValueComponent)

適用於