OperationContextScope Konstruktor
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.
Menginisialisasi instans baru dari kelas OperationContextScope.
Overload
| Nama | Deskripsi |
|---|---|
| OperationContextScope(IContextChannel) |
Menginisialisasi instans OperationContextScope baru kelas yang menggunakan yang ditentukan IContextChannel untuk membuat baru OperationContext untuk cakupan. |
| OperationContextScope(OperationContext) |
Menginisialisasi instans OperationContextScope baru kelas untuk membuat cakupan untuk objek yang ditentukan OperationContext . |
OperationContextScope(IContextChannel)
- Sumber:
- OperationContextScope.cs
- Sumber:
- OperationContextScope.cs
- Sumber:
- OperationContextScope.cs
Menginisialisasi instans OperationContextScope baru kelas yang menggunakan yang ditentukan IContextChannel untuk membuat baru OperationContext untuk cakupan.
public:
OperationContextScope(System::ServiceModel::IContextChannel ^ channel);
public OperationContextScope(System.ServiceModel.IContextChannel channel);
new System.ServiceModel.OperationContextScope : System.ServiceModel.IContextChannel -> System.ServiceModel.OperationContextScope
Public Sub New (channel As IContextChannel)
Parameter
- channel
- IContextChannel
Saluran yang digunakan saat membuat cakupan untuk baru OperationContext.
Contoh
Contoh berikut menunjukkan cara menggunakan OperationContextScope untuk membuat konteks baru dalam aplikasi klien untuk menambahkan header kustom ke pesan keluar.
SampleServiceClient wcfClient = new SampleServiceClient(new InstanceContext(this));
try
{
using (OperationContextScope scope = new OperationContextScope(wcfClient.InnerChannel))
{
MessageHeader header
= MessageHeader.CreateHeader(
"Service-Bound-CustomHeader",
"http://Microsoft.WCF.Documentation",
"Custom Happy Value."
);
OperationContext.Current.OutgoingMessageHeaders.Add(header);
// Making calls.
Console.WriteLine("Enter the greeting to send: ");
string greeting = Console.ReadLine();
//Console.ReadLine();
header = MessageHeader.CreateHeader(
"Service-Bound-OneWayHeader",
"http://Microsoft.WCF.Documentation",
"Different Happy Value."
);
OperationContext.Current.OutgoingMessageHeaders.Add(header);
// One-way
wcfClient.Push(greeting);
this.wait.WaitOne();
// Done with service.
wcfClient.Close();
Console.WriteLine("Done!");
Console.ReadLine();
}
}
catch (TimeoutException timeProblem)
{
Console.WriteLine("The service operation timed out. " + timeProblem.Message);
Console.ReadLine();
wcfClient.Abort();
}
catch (CommunicationException commProblem)
{
Console.WriteLine("There was a communication problem. " + commProblem.Message);
Console.ReadLine();
wcfClient.Abort();
}
Dim wcfClient As New SampleServiceClient(New InstanceContext(Me))
Try
Using scope As New OperationContextScope(wcfClient.InnerChannel)
Dim header As MessageHeader = MessageHeader.CreateHeader("Service-Bound-CustomHeader", _
"http://Microsoft.WCF.Documentation", "Custom Happy Value.")
OperationContext.Current.OutgoingMessageHeaders.Add(header)
' Making calls.
Console.WriteLine("Enter the greeting to send: ")
Dim greeting As String = Console.ReadLine()
'Console.ReadLine();
header = MessageHeader.CreateHeader("Service-Bound-OneWayHeader", _
"http://Microsoft.WCF.Documentation", "Different Happy Value.")
OperationContext.Current.OutgoingMessageHeaders.Add(header)
' One-way
wcfClient.Push(greeting)
Me.wait.WaitOne()
' Done with service.
wcfClient.Close()
Console.WriteLine("Done!")
Console.ReadLine()
End Using
Catch timeProblem As TimeoutException
Console.WriteLine("The service operation timed out. " & timeProblem.Message)
Console.ReadLine()
wcfClient.Abort()
Catch commProblem As CommunicationException
Console.WriteLine("There was a communication problem. " & commProblem.Message)
Console.ReadLine()
wcfClient.Abort()
End Try
Keterangan
OperationContextScope Gunakan konstruktor untuk membuat saluran klien baru OperationContext yang dapat digunakan untuk menambahkan atau memodifikasi header pesan keluar, membaca header pesan masuk, atau mengakses properti run-time lainnya dari OperationContext.
Header yang ditambahkan ke OperationContext.IncomingMessageHeaders properti yang baru dibuat OperationContext hanya berlaku untuk saluran yang diteruskan ke OperationContextScope konstruktor. Jika pengguna membuat saluran baru dalam cakupannya, header tidak diterapkan ke pesan yang dikirim di saluran baru.
Berlaku untuk
OperationContextScope(OperationContext)
- Sumber:
- OperationContextScope.cs
- Sumber:
- OperationContextScope.cs
- Sumber:
- OperationContextScope.cs
Menginisialisasi instans OperationContextScope baru kelas untuk membuat cakupan untuk objek yang ditentukan OperationContext .
public:
OperationContextScope(System::ServiceModel::OperationContext ^ context);
public OperationContextScope(System.ServiceModel.OperationContext context);
new System.ServiceModel.OperationContextScope : System.ServiceModel.OperationContext -> System.ServiceModel.OperationContextScope
Public Sub New (context As OperationContext)
Parameter
- context
- OperationContext
Aktif OperationContext dalam cakupan yang dibuat.
Keterangan
OperationContextScope Gunakan konstruktor untuk membuat blok kode di mana objek yang ditentukan OperationContextScope adalah cakupan saat ini.