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 方法不會) 將中繼資料新增至作業描述。 套用 WebGetAttribute 屬性至服務作業並不會起作用,除非在作業描述 (例如 WebHttpBehavior) 中尋找此中繼資料的行為,已新增至服務的行為集合中。

套用 WebGetAttribute 屬性的服務作業,應當為邏輯擷取作業。 HTTP GET 方法與所有標示為 WebGetAttribute 屬性的作業關聯。

建構函式

WebGetAttribute()

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

屬性

BodyStyle

取得或設定於服務作業來回傳送的訊息本文樣式。

IsBodyStyleSetExplicitly

取得 IsBodyStyleSetExplicitly 屬性。

IsRequestFormatSetExplicitly

取得 IsRequestFormatSetExplicitly 屬性。

IsResponseFormatSetExplicitly

取得 IsResponseFormatSetExplicitly 屬性。

RequestFormat

取得或設定 RequestFormat 屬性。

ResponseFormat

取得或設定 ResponseFormat 屬性。

TypeId

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

(繼承來源 Attribute)
UriTemplate

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

方法

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)
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) 方法。

適用於