WebGetAttribute 類別

定義

表示屬性,表示服務作業在邏輯上是擷取作業,而且可由WCF REST 程式設計模型呼叫。

public ref class WebGetAttribute sealed : Attribute, System::ServiceModel::Description::IOperationBehavior
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class WebGetAttribute : Attribute, System.ServiceModel.Description.IOperationBehavior
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type WebGetAttribute = class
    inherit Attribute
    interface IOperationBehavior
Public NotInheritable Class WebGetAttribute
Inherits Attribute
Implements IOperationBehavior
繼承
WebGetAttribute
屬性
實作

範例

以下範例說明如何使用該 WebGetAttribute 屬性。

[ServiceContract]
public interface ICalculator
{
    [OperationContract]
    [WebGet]
    long Add(long x, long y);

    [OperationContract]
    [WebGet(UriTemplate = "Sub?x={x}&y={y}")]
    long Subtract(long x, long y);

    [OperationContract]
    [WebGet(UriTemplate = "Mult?x={x}&y={y}", BodyStyle = WebMessageBodyStyle.Bare)]
    long Multiply(long x, long y);

    [OperationContract]
    [WebGet(UriTemplate = "Div?x={x}&y={y}", RequestFormat = WebMessageFormat.Xml)]
    long Divide(long x, long y);

    [OperationContract]
    [WebGet(ResponseFormat= WebMessageFormat.Json)]
    long Mod(long x, long y);
}
<ServiceContract()> _
Public Interface ICalculator
    <OperationContract()> _
    <WebGet()> _
    Function Add(ByVal x As Long, ByVal y As Long) As Long

    <OperationContract()> _
    <WebGet(UriTemplate:="Sub?x={x}&y={y}")> _
    Function Subtract(ByVal x As Long, ByVal y As Long) As Long

    <OperationContract()> _
    <WebGet(UriTemplate:="Mult?x={x}&y={y}", BodyStyle:=WebMessageBodyStyle.Bare)> _
    Function Multiply(ByVal x As Long, ByVal y As Long) As Long

    <OperationContract()> _
    <WebGet(UriTemplate:="Div?x={x}&y={y}", RequestFormat:=WebMessageFormat.Xml)> _
    Function Divide(ByVal x As Long, ByVal y As Long) As Long

    <OperationContract()> _
    <WebGet(ResponseFormat:=WebMessageFormat.Json)> _
    Function Modulo(ByVal x As Long, ByVal y As Long) As Long
End Interface

備註

屬性 WebGetAttribute 會套用到服務操作 OperationContractAttribute ,並將操作與 以及 UriTemplate HTTP 協定 Get 動詞相關聯。 HTTP Get 動詞的關聯表示該操作用於從服務中擷取資訊。 屬性 WebGetAttribute 是一種 被動 操作行為(方法 IOperationBehavior 不做任何事),會在操作描述中加入元資料。 除非將尋找該中繼資料的行為(例如 WebHttpBehavior)加入服務的行為集合,否則將屬性套用WebGetAttribute到服務操作操作中不會產生影響。

帶有屬性 WebGetAttribute 的服務操作應為邏輯檢索操作。 HTTP GET 方法與所有標記為 屬性 WebGetAttribute 的操作相關聯。

建構函式

名稱 Description
WebGetAttribute()

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

屬性

名稱 Description
BodyStyle

接收或設定發送至服務操作的訊息正文樣式。

IsBodyStyleSetExplicitly

取得該 IsBodyStyleSetExplicitly 物業。

IsRequestFormatSetExplicitly

取得該 IsRequestFormatSetExplicitly 物業。

IsResponseFormatSetExplicitly

取得該 IsResponseFormatSetExplicitly 物業。

RequestFormat

取得或設定該 RequestFormat 屬性。

ResponseFormat

取得或設定該 ResponseFormat 屬性。

TypeId

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

(繼承來源 Attribute)
UriTemplate

取得或設定服務操作的統一資源識別碼(URI)範本。

方法

名稱 Description
Equals(Object)

傳回值,這個值表示這個實例是否等於指定的物件。

(繼承來源 Attribute)
GetHashCode()

傳回這個實例的哈希碼。

(繼承來源 Attribute)
GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

明確介面實作

名稱 Description
_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)
IOperationBehavior.AddBindingParameters(OperationDescription, BindingParameterCollection)

實施該 AddBindingParameters(OperationDescription, BindingParameterCollection) 方法。

IOperationBehavior.ApplyClientBehavior(OperationDescription, ClientOperation)

實施該 ApplyClientBehavior(OperationDescription, ClientOperation) 方法。

IOperationBehavior.ApplyDispatchBehavior(OperationDescription, DispatchOperation)

實施該 ApplyDispatchBehavior(OperationDescription, DispatchOperation) 方法。

IOperationBehavior.Validate(OperationDescription)

實施該 Validate(OperationDescription) 方法。

適用於