OperationContextScope コンストラクター
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
OperationContextScope クラスの新しいインスタンスを初期化します。
オーバーロード
| 名前 | 説明 |
|---|---|
| OperationContextScope(IContextChannel) |
指定したIContextChannelを使用してスコープの新しいOperationContextを作成するOperationContextScope クラスの新しいインスタンスを初期化します。 |
| OperationContextScope(OperationContext) |
指定したOperationContext オブジェクトのスコープを作成するために、OperationContextScope クラスの新しいインスタンスを初期化します。 |
OperationContextScope(IContextChannel)
指定したIContextChannelを使用してスコープの新しいOperationContextを作成するOperationContextScope クラスの新しいインスタンスを初期化します。
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)
パラメーター
- channel
- IContextChannel
新しい OperationContextのスコープを作成するときに使用するチャネル。
例
次の例では、 OperationContextScope を使用してクライアント アプリケーションに新しいコンテキストを作成し、送信メッセージにカスタム ヘッダーを追加する方法を示します。
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
注釈
OperationContextScope コンストラクターを使用して、送信メッセージ ヘッダーの追加または変更、受信メッセージ ヘッダーの読み取り、またはOperationContextのその他の実行時プロパティへのアクセスに使用できるクライアント チャネルの新しいOperationContextを作成します。
新しく作成されたOperationContextのOperationContext.IncomingMessageHeaders プロパティに追加されたヘッダーは、OperationContextScope コンストラクターに渡されたチャネルにのみ適用されます。 ユーザーがそのスコープ内に新しいチャネルを作成した場合、ヘッダーは新しいチャネルで送信されたメッセージには適用されません。
適用対象
OperationContextScope(OperationContext)
指定したOperationContext オブジェクトのスコープを作成するために、OperationContextScope クラスの新しいインスタンスを初期化します。
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)
パラメーター
- context
- OperationContext
作成されたスコープ内のアクティブな OperationContext 。
注釈
OperationContextScope コンストラクターを使用して、指定したOperationContextScope オブジェクトが現在のスコープであるコード ブロックを作成します。