IContractBehaviorAttribute 인터페이스

정의

IContractBehavior 인터페이스를 구현하는 특성이 활성화되는 계약을 지정합니다.

public interface class IContractBehaviorAttribute
public interface IContractBehaviorAttribute
type IContractBehaviorAttribute = interface
Public Interface IContractBehaviorAttribute
파생

예제

다음 코드 예제에서는 사용자 지정 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

설명

서비스 유형에 대한 계약 동작 특성을 사용하려 하지만 IContractBehaviorAttribute 속성에 지정된 계약으로 적용을 제한하려면 System.ServiceModel.Description.IContractBehavior 개체이기도 한 특성에서 TargetContract 인터페이스를 구현합니다.

사용자 지정 계약 동작 특성에 대한 IContractBehaviorAttribute 구현 요구 사항은 없으며, 특성을 계약 인터페이스 또는 이중 콜백 클래스에 적용할 경우 TargetContract 속성 값은 무시됩니다.

자세한 내용은 System.ServiceModel.Description.IContractBehavior를 참조하세요.

속성

TargetContract

계약 동작을 적용할 수 있는 계약 형식을 가져옵니다.

적용 대상