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)을 구현하는 방법을 보여 줍니다. 또한 계약에 사용을 바인딩하는 구현 IContractBehaviorAttributeISampleService 구현합니다.

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

설명

ApplyDispatchBehavior 특정 계약의 모든 메시지 또는 해당 계약의 특정 작업에 대해 서비스 런타임에 사용자 지정 확장을 보거나 수정하거나 추가하는 방법을 구현합니다. 서비스 애플리케이션에서 수행할 수 있는 사용자 지정에 대한 자세한 내용은 DispatchRuntimeDispatchOperation을 참조하십시오.

ApplyDispatchBehavior 메서드는 동작이 클라이언트 애플리케이션에서만 사용되도록 지정된 경우 NotImplementedException 예외를 throw할 수 있습니다.

이 메서드는 지정된 서비스 계약을 사용하는 각 엔드포인트에 대해 한 번 호출됩니다.

설명에 이름이 같은 두 개의 작업(각 방향에 하나씩)이 있을 수 있으므로 계약이 이중 계약인 작업을 반복해야 하는 경우 엔드포인트 DispatchRuntime 와 속성에서 CallbackClientRuntime 반환된 메시지 방향 간의 상관 관계를 지정해야 합니다.

또한 다른 동작이 런타임에서 일부 작업을 이미 추가하거나 제거했을 수 있으므로 속성에 개체 Operations 가 있는 것과 설명에 동일한 수의 작업이 있다는 보장은 DispatchOperation 없습니다.

적용 대상