Bagikan melalui


WebInvokeAttribute Kelas

Definisi

Mewakili atribut yang menunjukkan bahwa operasi layanan secara logis merupakan operasi pemanggilan dan dapat dipanggil oleh model pemrograman 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
Warisan
WebInvokeAttribute
Atribut
Penerapan

Contoh

Contoh berikut menunjukkan cara menggunakan WebInvokeAttribute atribut .

Nota

Method Karena properti tidak ditentukan dalam kode berikut, semua operasi layanan dipetakan ke metode 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

Keterangan

Atribut WebInvokeAttribute diterapkan ke operasi layanan selain OperationContractAttribute dan mengaitkan operasi dengan UriTemplate serta kata kerja transportasi yang mendasar yang mewakili pemanggilan (misalnya, HTTP POST, PUT, atau DELETE). Atribut WebInvokeAttribute adalah perilaku operasi pasif ( IOperationBehavior metode tidak melakukan apa pun) yang menambahkan metadata ke deskripsi operasi. WebInvokeAttribute Menerapkan atribut ke operasi layanan tidak berpengaruh kecuali perilaku yang mencari metadata ini dalam deskripsi operasi (seperti WebHttpBehavior) ditambahkan ke kumpulan perilaku layanan. WebInvokeAttribute menentukan metode HTTP apa yang ditanggapi oleh operasi layanan. Secara default, semua metode yang menerapkan WebInvokeAttribute merespons permintaan POST. Properti Method memungkinkan Anda menentukan metode HTTP yang berbeda. Jika Anda ingin operasi layanan merespons GET, gunakan sebagai gantinya WebGetAttribute .

Konstruktor

Nama Deskripsi
WebInvokeAttribute()

Menginisialisasi instans baru dari kelas WebInvokeAttribute.

Properti

Nama Deskripsi
BodyStyle

Mendapatkan atau mengatur gaya isi pesan yang dikirim ke dan dari operasi layanan.

IsBodyStyleSetExplicitly

IsBodyStyleSetExplicitly Mendapatkan properti.

IsRequestFormatSetExplicitly

IsRequestFormatSetExplicitly Mendapatkan properti.

IsResponseFormatSetExplicitly

IsResponseFormatSetExplicitly Mendapatkan properti.

Method

Mendapatkan atau mengatur metode protokol (misalnya HTTP) yang ditanggapi operasi layanan.

RequestFormat

Mendapatkan atau mengatur RequestFormat properti.

ResponseFormat

Mendapatkan atau mengatur ResponseFormat properti.

TypeId

Ketika diimplementasikan dalam kelas turunan, mendapatkan pengidentifikasi unik untuk Attributeini.

(Diperoleh dari Attribute)
UriTemplate

Templat Pengidentifikasi Sumber Daya Seragam (URI) untuk operasi layanan.

Metode

Nama Deskripsi
Equals(Object)

Mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
GetHashCode()

Mengembalikan kode hash untuk instans ini.

(Diperoleh dari Attribute)
GetType()

Mendapatkan Type instans saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Ketika ditimpa dalam kelas turunan, menunjukkan apakah nilai instans ini adalah nilai default untuk kelas turunan.

(Diperoleh dari Attribute)
Match(Object)

Saat ditimpa dalam kelas turunan, mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
MemberwiseClone()

Membuat salinan dangkal dari Objectsaat ini.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

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

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari Attribute)
IOperationBehavior.AddBindingParameters(OperationDescription, BindingParameterCollection)

AddBindingParameters(OperationDescription, BindingParameterCollection) Menerapkan metode .

IOperationBehavior.ApplyClientBehavior(OperationDescription, ClientOperation)

ApplyClientBehavior(OperationDescription, ClientOperation) Menerapkan metode .

IOperationBehavior.ApplyDispatchBehavior(OperationDescription, DispatchOperation)

ApplyDispatchBehavior(OperationDescription, DispatchOperation) Menerapkan metode .

IOperationBehavior.Validate(OperationDescription)

Validate(OperationDescription) Menerapkan metode .

Berlaku untuk