IContractBehaviorAttribute.TargetContract プロパティ

定義

コントラクトの動作を適用できるコントラクトの型を取得します。

public:
 property Type ^ TargetContract { Type ^ get(); };
public Type TargetContract { get; }
member this.TargetContract : Type
Public ReadOnly Property TargetContract As Type

プロパティ値

Type

コントラクトの動作を適用できるコントラクト。

次のコード例は、カスタムの System.ServiceModel.Dispatcher.IInstanceProvider 実装が "シングルトン" 動作を提供する ObjectProviderBehavior を呼び出したことを前提としています。これは、常に同じサービス インスタンスを返し、リサイクルはしません。

インスタンス プロバイダーのカスタマイズを挿入するために、例では、SingletonBehaviorAttribute を実装するカスタム属性 (System.ServiceModel.Description.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

注釈

TargetContract 属性がサービス クラスに適用されるときにコントラクトの動作の適用対象となるコントラクトを指定する System.ServiceModel.Description.IContractBehavior プロパティを実装します。

適用対象