WebInvokeAttribute 類別

定義

代表屬性,這個屬性表示服務作業在邏輯上為叫用作業,可由 WCF REST 程式設計模型呼叫。

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

範例

下列範例會示範如何使用 WebInvokeAttribute 屬性。

注意

由於下列程式碼並未指定 Method 屬性,因此會將所有的服務作業對應至 HTTP POST 方法。

[ServiceContract]
public interface ICalculator2
{
    [OperationContract]
    [WebInvoke]
    long Add(long x, long y);

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

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

    [OperationContract]
    [WebInvoke(UriTemplate = "Div?x={x}&y={y}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat=WebMessageFormat.Xml)]
    long Divide(long x, long y);

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "Mod?x={x}&y={y}")]
    long Mod(long x, long y);
}
<ServiceContract()> _
Public Interface ICalculator2
    <OperationContract()> _
    <WebInvoke()> _
    Function Add(ByVal x As Long, ByVal y As Long) As Long

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

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

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

    <OperationContract()> _
   <WebInvoke(Method:="POST", UriTemplate:="Mod?x={x}&y={y}")> _
   Function Modulo(ByVal x As Long, ByVal y As Long) As Long
End Interface

備註

除了 WebInvokeAttribute 之外,還對服務作業套用 OperationContractAttribute 屬性,並且將作業與 UriTemplate 以及表示叫用的基礎傳輸動詞 (例如,HTTP POST、PUT 或 DELETE) 產生關聯。 屬性 WebInvokeAttribute被動 作業行為, (IOperationBehavior 方法不會執行任何動作,) 將中繼資料新增至作業描述。 套用 WebInvokeAttribute 屬性至服務作業並不會起作用,除非在作業描述 (例如 WebHttpBehavior) 中尋找此中繼資料的行為,已新增至服務的行為集合中。 WebInvokeAttribute 可決定服務作業所回應的 HTTP 方法。 根據預設,已套用 WebInvokeAttribute 的所有方法都會回應 POST 要求。 Method 屬性可讓您指定不同的 HTTP 方法。 如果您要服務作業回應 GET,請改為使用 WebGetAttribute

建構函式

WebInvokeAttribute()

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

屬性

BodyStyle

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

IsBodyStyleSetExplicitly

取得 IsBodyStyleSetExplicitly 屬性。

IsRequestFormatSetExplicitly

取得 IsRequestFormatSetExplicitly 屬性。

IsResponseFormatSetExplicitly

取得 IsResponseFormatSetExplicitly 屬性。

Method

取得或設定服務作業回應的通訊協定 (例如 HTTP) 方法。

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

適用於