IEndpointBehavior.ApplyDispatchBehavior 메서드

정의

엔드포인트에 대해 서비스의 수정이나 확장을 구현합니다.

public:
 void ApplyDispatchBehavior(System::ServiceModel::Description::ServiceEndpoint ^ endpoint, System::ServiceModel::Dispatcher::EndpointDispatcher ^ endpointDispatcher);
public void ApplyDispatchBehavior (System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher);
abstract member ApplyDispatchBehavior : System.ServiceModel.Description.ServiceEndpoint * System.ServiceModel.Dispatcher.EndpointDispatcher -> unit
Public Sub ApplyDispatchBehavior (endpoint As ServiceEndpoint, endpointDispatcher As EndpointDispatcher)

매개 변수

endpoint
ServiceEndpoint

계약을 공개하는 엔드포인트입니다.

endpointDispatcher
EndpointDispatcher

수정하거나 확장할 엔드포인트 디스패처입니다.

예제

다음 코드 예제에서는 서비스 애플리케이션에서 System.ServiceModel.Dispatcher.IDispatchMessageInspector 개체를 추가하는 엔드포인트 동작의 구현을 보여 줍니다. 이 경우 EndpointBehaviorMessageInspector 클래스는 System.ServiceModel.Dispatcher.IDispatchMessageInspector를 구현하여 인바운드 및 아웃바운드 메시지를 검사하고, IEndpointBehavior 인터페이스를 구현하여 동작이 적용되는 모든 엔드포인트에 대한 검사 시스템에 inspector 클래스를 삽입하며, System.ServiceModel.Configuration.BehaviorExtensionElement를 구현함으로써 애플리케이션 구성 파일을 사용하여 메시지 검사자 동작을 활성화합니다.

첫 번째 단계는 메시지 검사기를 구현하는 것입니다.

// IDispatchMessageInspector Members

public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
{
  Console.WriteLine("AfterReceiveRequest called.");
  return null;
}

public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
  Console.WriteLine("BeforeSendReply called.");
}

다음 코드 예제에서는 메서드를 ApplyDispatchBehavior 사용하여 속성에 메시지 검사기를 추가하는 방법을 DispatchRuntime.MessageInspectors 보여줍니다.

// IEndpointBehavior Members
public void AddBindingParameters(ServiceEndpoint serviceEndpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
  return;
}

public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior)
{
  behavior.MessageInspectors.Add(new EndpointBehaviorMessageInspector());
}

public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
{
  endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new EndpointBehaviorMessageInspector());
}

public void Validate(ServiceEndpoint serviceEndpoint)
{
  return;
}

다음 코드 예제에서는 구성 파일에서 메시지 검사기 동작을 사용할 수 있도록 하기 위한 구현 System.ServiceModel.Configuration.BehaviorExtensionElement 을 보여 줍니다.

// BehaviorExtensionElement members
public override Type BehaviorType
{
  get { return typeof(EndpointBehaviorMessageInspector); }
}

protected override object CreateBehavior()
{
  return new EndpointBehaviorMessageInspector();
}

마지막으로 다음 구성 파일은 이전 예제를 구성에서 사용할 수 있는 방법을 보여줍니다.

<configuration>
  <system.serviceModel>
    <services>
      <service 
        name="Microsoft.WCF.Documentation.SampleService"
        behaviorConfiguration="metadataSupport"
      >
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/ServiceMetadata" />
          </baseAddresses>
        </host>
        <endpoint
          address="/SampleService"
          binding="wsHttpBinding"
          behaviorConfiguration="withMessageInspector" 
          contract="Microsoft.WCF.Documentation.ISampleService"
        />
        <endpoint
           address="mex"
           binding="mexHttpBinding"
           contract="IMetadataExchange"
        />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
      <behavior name="metadataSupport">
        <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
      </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="withMessageInspector">
          <endpointMessageInspector />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <extensions>
      <behaviorExtensions>
        <add 
          name="endpointMessageInspector"
          type="Microsoft.WCF.Documentation.EndpointBehaviorMessageInspector, HostApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
        />
      </behaviorExtensions>
    </extensions>
  </system.serviceModel>
</configuration>

설명

ApplyDispatchBehavior 모든 메시지 또는 엔드포인트의 특정 작업에 대해 서비스 런타임을 보거나 수정하거나 확장하는 메서드를 구현합니다. 서비스 애플리케이션에서 수행할 수 있는 사용자 지정에 대한 자세한 내용은 System.ServiceModel.Dispatcher.DispatchRuntimeSystem.ServiceModel.Dispatcher.DispatchOperation을 참조하십시오.

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

콜백 계약을 사용할 때 설명에 이름이 같은 두 개의 작업이 있을 수 있습니다(각 방향에서 하나의 작업). 작업을 반복하는 경우 엔드포인트 System.ServiceModel.Dispatcher.DispatchRuntime 와 속성에서 반환 DispatchRuntime.CallbackClientRuntime 되는 메시지 방향 간의 상관 관계를 지정해야 합니다.

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

적용 대상