CallbackBehaviorAttribute クラス
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
クライアント アプリケーションでのコールバック サービス実装を構成します。
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
- 継承
- 属性
- 実装
CallbackBehaviorAttribute オブジェクトを使用してマーシャリングするスレッドを決定するコールバック オブジェクトの SynchronizationContext、メッセージ検証を実施する ValidateMustUnderstand プロパティ、および例外を IncludeExceptionDetailInFaults オブジェクトとしてデバッグ用のサービスに返す FaultException プロパティのコード例を次に示します。
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
CallbackBehaviorAttribute 属性を使用して、クライアント アプリケーションでのコールバック コントラクトの実装の実行動作を構成または拡張します。 この属性は、インスタンス化動作とトランザクションの設定を除き、ServiceBehaviorAttribute 属性と同じ機能をコールバック クラスに対して実行します。
CallbackBehaviorAttribute は、コールバック コントラクトを実装するクラスに適用する必要があります。 双方向以外のコントラクト実装に適用した場合は、実行時に InvalidOperationException 例外がスローされます。
注意
コールバック操作の実装に対して OperationBehaviorAttribute 属性を使用することもできます。 ただし、OperationBehaviorAttribute をコールバック操作で使用する場合は、ReleaseInstanceMode プロパティが None でなければなりません。そうでない場合は、実行時に InvalidOperationException 例外がスローされます。
使用できるプロパティは次のとおりです。
AutomaticSessionShutdown プロパティは、チャネルが閉じられ、残っているすべてのメッセージの処理をコールバックが終了した時点でセッションを自動的に閉じます。
ConcurrencyMode プロパティは、内部スレッド モデルを制御して、再入可能またはマルチスレッド コールバック オブジェクトのサポートを有効にします。
IgnoreExtensionDataObject プロパティは、メッセージの処理では必要がない余分なシリアル化情報をランタイムが無視できるようにします。
IncludeExceptionDetailInFaults プロパティは、サービス内の未処理例外を、デバッグ用に SOAP エラーとしてサービスに返すかどうかを指定します。
MaxItemsInObjectGraph プロパティは、シリアル化されるオブジェクト グラフ内の項目数を制限します。
TransactionIsolationLevel プロパティは、コントラクトがサポートするトランザクションの分離レベルを指定します。
TransactionTimeout プロパティは、トランザクションを完了しなければならない期間を指定します。この期間内に完了しない場合、トランザクションは中止されます。
UseSynchronizationContext プロパティは、現在の SynchronizationContext オブジェクトを使用して、受信メソッドの呼び出しを同期するかどうかを示します。
ValidateMustUnderstand プロパティは、
MustUnderstand
としてマークされた SOAP ヘッダーが間違いなく理解されたことを確認する必要があるかどうかをシステムに通知します。
Callback |
CallbackBehaviorAttribute クラスの新しいインスタンスを初期化します。 |
Automatic |
サービスが双方向セッションを閉じたときに、セッションを自動的に閉じるかどうかを指定します。 |
Concurrency |
サービスが、1 つのスレッド、複数のスレッド、または再入呼び出しをサポートするかどうかを示す値を取得または設定します。 |
Ignore |
不明なシリアル化データをネットワークで送信するかどうかを指定する値を取得または設定します。 |
Include |
一般的な未処理の実行例外を FaultException<TDetail> 型の String に変換してエラー メッセージとして送信するように指定する値を取得または設定します。 この属性は、開発時にサービスのトラブルシューティングを行う場合にのみ、 |
Max |
シリアル化されるオブジェクトで許可される項目の最大数を取得または設定します。 |
Transaction |
トランザクション分離レベルを指定します。 |
Transaction |
トランザクションを完了する必要がある制限時間を取得または設定します。 |
Type |
派生クラスで実装されると、この Attribute の一意の識別子を取得します。 (継承元 Attribute) |
Use |
現在の同期コンテキストを使用して実行スレッドを選択するかどうかを指定する値を取得または設定します。 |
Validate |
システムまたはアプリケーションで SOAP |
Equals(Object) |
このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。 (継承元 Attribute) |
Get |
このインスタンスのハッシュ コードを返します。 (継承元 Attribute) |
Get |
現在のインスタンスの Type を取得します。 (継承元 Object) |
Is |
派生クラスでオーバーライドされるとき、このインスタンスの値が派生クラスの既定値であるかどうかを示します。 (継承元 Attribute) |
Match(Object) |
派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (継承元 Attribute) |
Memberwise |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
To |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
_Attribute. |
一連の名前を対応する一連のディスパッチ識別子に割り当てます。 (継承元 Attribute) |
_Attribute. |
オブジェクトの型情報を取得します。この情報はインターフェイスの型情報の取得に使用できます。 (継承元 Attribute) |
_Attribute. |
オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。 (継承元 Attribute) |
_Attribute. |
オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。 (継承元 Attribute) |
IEndpoint |
バインド要素を、コールバック動作をサポートするように構成します。 |
IEndpoint |
クライアント ランタイムを、コールバック オブジェクトをサポートするように構成します。 |
IEndpoint |
ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher) メソッドの実装。 この実装は、効果がありません。 |
IEndpoint |
ランタイムを構築する前に、エンドポイントの説明を検証します。 |
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1 |
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 |
UWP | 10.0 |