IContractBehavior.ApplyDispatchBehavior メソッド

定義

コントラクト全体にわたってクライアントの変更または拡張を実装します。

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
}
Public Class SingletonBehaviorAttribute
    Inherits Attribute
    Implements IContractBehaviorAttribute, IContractBehavior

  #Region "IContractBehaviorAttribute Members"

  Public ReadOnly Property TargetContract() As Type Implements IContractBehaviorAttribute.TargetContract
    Get
        Return GetType(ISampleService)
    End Get
  End Property

  #End Region

  #Region "IContractBehavior Members"

  Public Sub AddBindingParameters(ByVal description As ContractDescription, ByVal endpoint As ServiceEndpoint, ByVal parameters As System.ServiceModel.Channels.BindingParameterCollection) Implements IContractBehavior.AddBindingParameters
    Return
  End Sub

  Public Sub ApplyClientBehavior(ByVal description As ContractDescription, ByVal endpoint As ServiceEndpoint, ByVal clientRuntime As ClientRuntime) Implements IContractBehavior.ApplyClientBehavior
    Return
  End Sub

  Public Sub ApplyDispatchBehavior(ByVal description As ContractDescription, ByVal endpoint As ServiceEndpoint, ByVal dispatch As DispatchRuntime) Implements IContractBehavior.ApplyDispatchBehavior
    dispatch.InstanceProvider = New ObjectProviderBehavior("Custom ObjectProviderBehavior constructor.")
  End Sub

  Public Sub Validate(ByVal description As ContractDescription, ByVal endpoint As ServiceEndpoint) Implements IContractBehavior.Validate
    Return
  End Sub

  #End Region
End Class

注釈

特定のコントラクト内のすべてのメッセージまたはそのコントラクト内の特定の 1 つの操作について、サービス ランタイムを表示または変更したり、サービス ランタイムにカスタム拡張機能を追加したりするには、ApplyDispatchBehavior を実装します。 サービス アプリケーションで実行できるカスタマイズの詳細については、DispatchRuntime および DispatchOperation を参照してください。

動作をクライアント アプリケーションでのみ使用する場合は、ApplyDispatchBehavior メソッドによって NotImplementedException 例外をスローすることができます。

このメソッドは、指定されたサービス コントラクトを使用するエンドポイントごとに 1 回呼び出されます。

説明 (各方向に 1 つずつ) では同じ名前の操作が 2 つ存在する場合がありますので注意してください。このため、双方向コントラクトで操作の反復が必要な場合は、エンドポイント DispatchRuntime と、CallbackClientRuntime プロパティによって返されるエンドポイント間で、メッセージの方向を関連付ける必要があります。

また、既に他の動作によって一部の操作が追加されるか、ランタイムから削除されている可能性があるので、DispatchOperation プロパティにある Operations オブジェクトと同じ数の操作が説明に存在するという保証はありません。

適用対象