IContractBehavior.ApplyDispatchBehavior メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
コントラクト全体でクライアントの変更または拡張を実装します。
public:
void ApplyDispatchBehavior(System::ServiceModel::Description::ContractDescription ^ contractDescription, System::ServiceModel::Description::ServiceEndpoint ^ endpoint, System::ServiceModel::Dispatcher::DispatchRuntime ^ dispatchRuntime);
public void ApplyDispatchBehavior(System.ServiceModel.Description.ContractDescription contractDescription, System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.DispatchRuntime dispatchRuntime);
abstract member ApplyDispatchBehavior : System.ServiceModel.Description.ContractDescription * System.ServiceModel.Description.ServiceEndpoint * System.ServiceModel.Dispatcher.DispatchRuntime -> unit
Public Sub ApplyDispatchBehavior (contractDescription As ContractDescription, endpoint As ServiceEndpoint, dispatchRuntime As DispatchRuntime)
パラメーター
- contractDescription
- ContractDescription
変更するコントラクトの説明。
- endpoint
- ServiceEndpoint
コントラクトを公開するエンドポイント。
- dispatchRuntime
- DispatchRuntime
サービスの実行を制御するディスパッチ ランタイム。
例
次のコード例では、"シングルトン" 動作を提供する IInstanceProvider と呼ばれるカスタム ObjectProviderBehavior実装を想定しています。これは常に同じサービス インスタンスを返し、リサイクルしません。
インスタンス プロバイダーのカスタマイズを挿入するために、この例では、カスタム サービス インスタンス プロバイダーを挿入するSingletonBehaviorAttributeを実装するカスタム属性 (IContractBehavior) を実装する方法を示します。 また、IContractBehaviorAttribute コントラクトに使用をバインドするISampleServiceも実装します。
public class SingletonBehaviorAttribute : Attribute, IContractBehaviorAttribute, IContractBehavior
{
#region IContractBehaviorAttribute Members
public Type TargetContract
{
get { return typeof(ISampleService); }
}
#endregion
#region IContractBehavior Members
public void AddBindingParameters(ContractDescription description, ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection parameters)
{
return;
}
public void ApplyClientBehavior(ContractDescription description, ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
return;
}
public void ApplyDispatchBehavior(ContractDescription description, ServiceEndpoint endpoint, DispatchRuntime dispatch)
{
dispatch.InstanceProvider = new ObjectProviderBehavior("Custom ObjectProviderBehavior constructor.");
}
public void Validate(ContractDescription description, ServiceEndpoint endpoint)
{
return;
}
#endregion
}
注釈
特定のコントラクト内のすべてのメッセージ、またはそのコントラクト内の 1 つの特定の操作について、サービス ランタイムにカスタム拡張機能を表示、変更、または追加する ApplyDispatchBehavior を実装します。 サービス アプリケーションで実行できるカスタマイズの詳細については、「 DispatchRuntime と DispatchOperation」を参照してください。
動作がクライアント アプリケーションでのみ使用される場合、 ApplyDispatchBehavior メソッドは NotImplementedException 例外をスローできます。
このメソッドは、指定されたサービス コントラクトを使用するエンドポイントごとに 1 回呼び出されます。
説明には同じ名前を持つ 2 つの操作 (各方向に 1 つずつ) が存在する可能性があるため、コントラクトが双方向コントラクトである操作を反復処理する必要がある場合は、エンドポイント DispatchRuntime と CallbackClientRuntime プロパティによって返されるメッセージの方向を関連付ける必要があります。
さらに、他の動作によってランタイムから一部の操作が既に追加または削除されている可能性があるため、DispatchOperation プロパティにOperationsオブジェクトがある場合と同じ数の操作が説明に含まれるという保証はありません。