WebServiceAttribute 類別

定義

用來將其他資訊加入 XML Web Service,例如描述其功能的字串。

public ref class WebServiceAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class WebServiceAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface)]
public sealed class WebServiceAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type WebServiceAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface)>]
type WebServiceAttribute = class
    inherit Attribute
Public NotInheritable Class WebServiceAttribute
Inherits Attribute
繼承
WebServiceAttribute
屬性

範例

下列範例會將 DescriptionWebServiceAttribute 屬性設定為 "Common Server Variables" ,並將 XML 命名空間設定為 http://www.microsoft.com/

<%@ WebService Language="C#" Class= "ServerVariables"%>
 
 using System;
 using System.Web.Services;
 
 [ WebService(Description="Common Server Variables",Namespace="http://www.contoso.com/")]
 public class ServerVariables: WebService {
 
 
    [ WebMethod(Description="Obtains the Server Computer Name",EnableSession=false)]
    public string GetMachineName() {
       return Server.MachineName;
    }   
 }
<%@ WebService Language="VB" Class= "ServerVariables"%>
 
Imports System
Imports System.Web.Services

<WebService(Description := "Common Server Variables", _
 Namespace := "http://www.contoso.com/")> _
Public Class ServerVariables
    Inherits WebService 
    
    <WebMethod(Description := "Obtains the Computer Machine Name", _
        EnableSession := False)> _
    Public Function GetMachineName() As String
        
        Return Server.MachineName
    End Function
End Class

備註

WebServiceAttributeXML Web 服務不需要發佈和執行 。 您可以使用 WebServiceAttribute 來指定 XML Web 服務的名稱,該名稱不受 Common Language Runtime 識別碼的規則所限制,此識別碼用於服務描述和服務說明頁面的 XML Web 服務。

XML Web 服務應該先變更其預設 XML 命名空間,再將其設為公用。 每個 XML Web 服務都需要唯一的 XML 命名空間來識別它,讓用戶端應用程式可以區別它與網路上的其他服務。 http://tempuri.org/ 適用于開發中的 XML Web 服務,但已發佈的 XML Web 服務應該使用更永久的命名空間。

XML Web 服務應該由您所控制的 XML 命名空間來識別。 例如,您可以使用公司的網際網路功能變數名稱作為 XML 命名空間的一部分。 雖然許多 XML Web 服務 XML 命名空間看起來像 URL,但不需要指向網路上的實際資源。 (XML Web 服務 XML 命名空間是 URI.) 針對使用 ASP.NET 建立的 XML Web 服務,可以使用 屬性來變更 Namespace 預設 XML 命名空間。

如需使用屬性的詳細資訊,請參閱 屬性

建構函式

WebServiceAttribute()

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

欄位

DefaultNamespace

Namespace 屬性的預設值。 這個欄位為常數。

屬性

Description

XML Web Service 的描述性訊息。

Name

取得或設定 XML Web Service 的名稱。

Namespace

取得或設定要使用於 XML Web Service 的預設 XML 命名空間。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱