WebService 類別

定義

定義 XML Web Service 的選擇性 (Optional) 基底類別,這類別提供對通用 ASP.NET 物件 (例如應用程式和工作階段 (Session) 狀態) 的直接存取。

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 服務,以便使用 Context 屬性來取得伺服器上的要求時間。

<%@ 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 服務,而不需要衍生自 WebService 。 您可以透過 Context 存取其他 ASP.NET 物件。

XML Web 服務方法,其 OneWay 屬性為 或 SoapDocumentMethodAttribute 設定為 true ,則無法存取其 HttpContextSoapRpcMethodAttribute 。 因此,從該 XML Web 服務方法記憶體取 類別的任何屬性 WebService ,會傳回 null

如果您使用 .NET Framework 1.0 版 XML Web 服務方法,這些方法已 SoapRpcMethodAttribute 將 或 SoapDocumentMethodAttribute 屬性套用至它們 OneWay ,且 屬性設為 true ,則無法使用靜態 Current 屬性存取它們 HttpContext 。 若要存取 HttpContext ,請從 WebService 衍生實作 XML Web 服務方法的 類別,並存取 Context 屬性。

建構函式

WebService()

初始化 WebService 類別的新執行個體。

屬性

Application

取得目前 HTTP 要求的應用程式物件。

Container

取得元件的容器。

(繼承來源 MarshalByValueComponent)
Context

取得目前要求的 ASP.NET HttpContext 將 HTTP 伺服器使用的所有 HTTP 特定內容封裝,以便處理 Web 要求。

DesignMode

取得值,表示元件目前是否處於設計模式。

(繼承來源 MarshalByValueComponent)
Events

取得附加在這個元件上的事件處理常式清單。

(繼承來源 MarshalByValueComponent)
Server

取得目前要求的 HttpServerUtility

Session

取得目前要求的 HttpSessionState

Site

取得或設定元件的網站。

(繼承來源 MarshalByValueComponent)
SoapVersion

取得向 XML Web Service 提出 SOAP 要求時所使用的 SOAP 通訊協定版本。

User

取得 ASP.NET 伺服器 User 物件。 可用來驗證是否授權使用者執行要求。

方法

Dispose()

釋放 MarshalByValueComponent 所使用的所有資源。

(繼承來源 MarshalByValueComponent)
Dispose(Boolean)

釋放 MarshalByValueComponent 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 MarshalByValueComponent)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetService(Type)

取得 IServiceProvider 的實作器。

(繼承來源 MarshalByValueComponent)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回任何包含 Component 名稱的 String。 不應覆寫此方法。

(繼承來源 MarshalByValueComponent)

事件

Disposed

加入事件處理常式來接聽元件上的 Disposed 事件。

(繼承來源 MarshalByValueComponent)

適用於