CallbackBehaviorAttribute Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengonfigurasi implementasi layanan panggilan balik dalam aplikasi klien.
public ref class CallbackBehaviorAttribute sealed : Attribute, System::ServiceModel::Description::IEndpointBehavior
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class CallbackBehaviorAttribute : Attribute, System.ServiceModel.Description.IEndpointBehavior
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type CallbackBehaviorAttribute = class
inherit Attribute
interface IEndpointBehavior
Public NotInheritable Class CallbackBehaviorAttribute
Inherits Attribute
Implements IEndpointBehavior
- Warisan
- Atribut
- Penerapan
Contoh
Contoh kode berikut menunjukkan CallbackBehaviorAttribute pada objek panggilan balik yang menggunakan objek untuk menentukan utas SynchronizationContext mana yang akan di-marshal, ValidateMustUnderstand properti untuk memberlakukan validasi pesan, dan IncludeExceptionDetailInFaults properti untuk mengembalikan pengecualian sebagai FaultException objek ke layanan untuk tujuan penelusuran kesalahan.
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Threading;
namespace Microsoft.WCF.Documentation
{
[CallbackBehaviorAttribute(
IncludeExceptionDetailInFaults= true,
UseSynchronizationContext=true,
ValidateMustUnderstand=true
)]
public class Client : SampleDuplexHelloCallback
{
AutoResetEvent waitHandle;
public Client()
{
waitHandle = new AutoResetEvent(false);
}
public void Run()
{
// Picks up configuration from the configuration file.
SampleDuplexHelloClient wcfClient
= new SampleDuplexHelloClient(new InstanceContext(this), "WSDualHttpBinding_SampleDuplexHello");
try
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Enter a greeting to send and press ENTER: ");
Console.Write(">>> ");
Console.ForegroundColor = ConsoleColor.Green;
string greeting = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Called service with: \r\n\t" + greeting);
wcfClient.Hello(greeting);
Console.WriteLine("Execution passes service call and moves to the WaitHandle.");
this.waitHandle.WaitOne();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Set was called.");
Console.Write("Press ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("ENTER");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write(" to exit...");
Console.ReadLine();
}
catch (TimeoutException timeProblem)
{
Console.WriteLine("The service operation timed out. " + timeProblem.Message);
Console.ReadLine();
}
catch (CommunicationException commProblem)
{
Console.WriteLine("There was a communication problem. " + commProblem.Message);
Console.ReadLine();
}
}
public static void Main()
{
Client client = new Client();
client.Run();
}
public void Reply(string response)
{
Console.WriteLine("Received output.");
Console.WriteLine("\r\n\t" + response);
this.waitHandle.Set();
}
}
}
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Threading
Namespace Microsoft.WCF.Documentation
<CallbackBehaviorAttribute(IncludeExceptionDetailInFaults:= True, UseSynchronizationContext:=True, ValidateMustUnderstand:=True)> _
Public Class Client
Implements SampleDuplexHelloCallback
Private waitHandle As AutoResetEvent
Public Sub New()
waitHandle = New AutoResetEvent(False)
End Sub
Public Sub Run()
' Picks up configuration from the configuration file.
Dim wcfClient As New SampleDuplexHelloClient(New InstanceContext(Me), "WSDualHttpBinding_SampleDuplexHello")
Try
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine("Enter a greeting to send and press ENTER: ")
Console.Write(">>> ")
Console.ForegroundColor = ConsoleColor.Green
Dim greeting As String = Console.ReadLine()
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine("Called service with: " & Constants.vbCrLf & Constants.vbTab & greeting)
wcfClient.Hello(greeting)
Console.WriteLine("Execution passes service call and moves to the WaitHandle.")
Me.waitHandle.WaitOne()
Console.ForegroundColor = ConsoleColor.Blue
Console.WriteLine("Set was called.")
Console.Write("Press ")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("ENTER")
Console.ForegroundColor = ConsoleColor.Blue
Console.Write(" to exit...")
Console.ReadLine()
Catch timeProblem As TimeoutException
Console.WriteLine("The service operation timed out. " & timeProblem.Message)
Console.ReadLine()
Catch commProblem As CommunicationException
Console.WriteLine("There was a communication problem. " & commProblem.Message)
Console.ReadLine()
End Try
End Sub
Public Shared Sub Main()
Dim client As New Client()
client.Run()
End Sub
Public Sub Reply(ByVal response As String) Implements SampleDuplexHelloCallback.Reply
Console.WriteLine("Received output.")
Console.WriteLine(Constants.vbCrLf & Constants.vbTab & response)
Me.waitHandle.Set()
End Sub
End Class
End Namespace
Keterangan
CallbackBehaviorAttribute Gunakan atribut untuk mengonfigurasi atau memperluas perilaku eksekusi implementasi kontrak panggilan balik dalam aplikasi klien. Atribut ini melakukan fungsi yang sama untuk kelas panggilan balik sebagai ServiceBehaviorAttribute atribut dengan pengecualian perilaku instancing dan pengaturan transaksi.
CallbackBehaviorAttribute harus diterapkan ke kelas yang mengimplementasikan kontrak panggilan balik. Jika diterapkan pada implementasi InvalidOperationException kontrak non-dupleks, pengecualian akan dilemparkan pada runtime.
Nota
Anda juga dapat menggunakan OperationBehaviorAttribute atribut untuk implementasi operasi panggilan balik. Namun, jika OperationBehaviorAttribute digunakan pada operasi panggilan balik, ReleaseInstanceMode properti harus None atau InvalidOperationException pengecualian dilemparkan pada runtime.
Properti berikut ini tersedia:
Properti AutomaticSessionShutdown secara otomatis menutup sesi ketika saluran ditutup dan panggilan balik telah selesai memproses pesan yang tersisa.
Properti ConcurrencyMode mengontrol model utas internal, memungkinkan dukungan untuk objek panggilan balik yang masuk kembali atau multithreaded.
Properti IgnoreExtensionDataObject memungkinkan runtime untuk mengabaikan informasi serialisasi tambahan yang tidak diperlukan untuk memproses pesan.
Properti IncludeExceptionDetailInFaults menentukan apakah pengecualian yang tidak tertangani dalam layanan dikembalikan ke layanan sebagai kesalahan SOAP untuk tujuan penelusuran kesalahan.
Properti MaxItemsInObjectGraph membatasi jumlah item dalam grafik objek yang diserialisasikan.
Properti TransactionIsolationLevel menentukan tingkat isolasi transaksi yang didukung kontrak.
Properti TransactionTimeout menentukan periode waktu di mana transaksi harus selesai atau dibatalkan.
Properti UseSynchronizationContext menunjukkan apakah akan menyinkronkan panggilan metode masuk secara otomatis menggunakan objek saat ini SynchronizationContext .
Properti ValidateMustUnderstand menginformasikan sistem apakah harus mengonfirmasi bahwa header SOAP yang ditandai sebagai
MustUnderstandtelah, pada kenyataannya, telah dipahami.
Konstruktor
| Nama | Deskripsi |
|---|---|
| CallbackBehaviorAttribute() |
Menginisialisasi instans baru dari kelas CallbackBehaviorAttribute. |
Properti
| Nama | Deskripsi |
|---|---|
| AutomaticSessionShutdown |
Menentukan apakah akan menutup sesi secara otomatis saat layanan menutup sesi dupleks. |
| ConcurrencyMode |
Mendapatkan atau mengatur apakah layanan mendukung satu utas, beberapa utas, atau panggilan masuk kembali. |
| IgnoreExtensionDataObject |
Mendapatkan atau menetapkan nilai yang menentukan apakah akan mengirim data serialisasi yang tidak diketahui ke kawat. |
| IncludeExceptionDetailInFaults |
Mendapatkan atau menetapkan nilai yang menentukan bahwa pengecualian eksekusi umum yang tidak tertangani akan dikonversi menjadi FaultException<TDetail> jenis String dan dikirim sebagai pesan kesalahan. Atur ini ke |
| MaxItemsInObjectGraph |
Mendapatkan atau mengatur jumlah maksimum item yang diizinkan dalam objek berseri. |
| TransactionIsolationLevel |
Menentukan tingkat isolasi transaksi. |
| TransactionTimeout |
Mendapatkan atau menetapkan periode di mana transaksi harus diselesaikan. |
| TypeId |
Ketika diimplementasikan dalam kelas turunan, mendapatkan pengidentifikasi unik untuk Attributeini. (Diperoleh dari Attribute) |
| UseSynchronizationContext |
Mendapatkan atau menetapkan nilai yang menentukan apakah akan menggunakan konteks sinkronisasi saat ini untuk memilih utas eksekusi. |
| ValidateMustUnderstand |
Mendapatkan atau menetapkan nilai yang menentukan apakah sistem atau aplikasi memberlakukan pemrosesan header SOAP |
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) |
| IEndpointBehavior.AddBindingParameters(ServiceEndpoint, BindingParameterCollection) |
Mengonfigurasi elemen pengikatan untuk mendukung perilaku panggilan balik. |
| IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint, ClientRuntime) |
Mengonfigurasi runtime klien untuk mendukung objek panggilan balik. |
| IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher) |
ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher) Implementasi metode . Implementasi ini tidak berpengaruh. |
| IEndpointBehavior.Validate(ServiceEndpoint) |
Memvalidasi deskripsi titik akhir sebelum membuat runtime. |