IEndpointBehavior 인터페이스

정의

서비스 또는 클라이언트 애플리케이션에서 엔드포인트에 대한 런타임 동작을 확장하는 데 사용할 수 있는 메서드를 구현합니다.

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

예제

다음 코드 예제에서는 서비스 애플리케이션에서 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>

설명

클라이언트 또는 서버 애플리케이션에 대해 애플리케이션 수준에서 엔드포인트 차원 실행의 일부 측면을 수정, 검사 또는 확장하기 위한 IEndpointBehavior 인터페이스를 구현합니다.

  • 이 메서드를 AddBindingParameters 사용하여 런타임에 사용자 지정 데이터를 전달하여 바인딩이 사용자 지정 동작을 지원할 수 있도록 합니다.

  • 클라이언트 애플리케이션에서 엔드포인트에 대한 확장을 수정, 검사 또는 삽입하려면 ApplyClientBehavior 메서드를 사용합니다.

  • 클라이언트 애플리케이션에서 엔드포인트 차원의 실행에 대한 확장을 수정, 검사 또는 삽입하려면 ApplyDispatchBehavior 메서드를 사용합니다.

  • 메서드를 Validate 사용하여 특정 요구 사항을 충족하는지 ServiceEndpoint 확인합니다. 엔드포인트에 특정 구성 설정을 사용하도록 설정하고 특정 기능 및 기타 요구 사항을 지원하는 데 사용할 수 있습니다.

IEndpointBehavior 개체는 이러한 메서드를 사용할 수 있지만 종종 하나만 중요합니다. 이러한 경우 사용되지 않는 메서드는 아무 작업도 수행하지 않고 반환할 수 있습니다.

참고

모든 메서드는 IEndpointBehavior 개체를 ServiceEndpoint 매개 변수로 전달합니다. 이 매개 변수는 검사 전용입니다. 개체를 ServiceEndpoint 수정하면 실행 동작이 정의되지 않습니다.

IEndpointBehavior 개체는 일반적으로 서비스 애플리케이션의 System.ServiceModel.Dispatcher.DispatchRuntime, System.ServiceModel.Dispatcher.DispatchOperation, System.ServiceModel.Dispatcher.EndpointDispatcherSystem.ServiceModel.Dispatcher.ChannelDispatcher 개체의 다양한 속성과 클라이언트 애플리케이션의 System.ServiceModel.Dispatcher.ClientRuntimeSystem.ServiceModel.Dispatcher.ClientOperation의 다양한 속성을 액세스하는 데 사용됩니다. 또한 각각 및 DispatchRuntime.CallbackClientRuntime 속성을 사용하여 이중 클라이언트 및 서비스의 속성에 ClientRuntime.CallbackDispatchRuntime 액세스할 수 있습니다.

사용 가능한 다양한 속성 및 사용자 지정에 대한 설명은 ServiceHost 및 서비스 모델 계층 확장을 참조하세요.

사용자 지정이 결정되고 필요한 경우 구현된 사용자 지정 인터페이스가 IEndpointBehavior 적절한 사용자 지정 범위로 결정되면 런타임에 엔드포인트 동작을 구현 IEndpointBehavior 하고 추가하여 사용자 지정을 Windows Communication Foundation(WCF) 런타임에 삽입해야 합니다.

런타임에 동작을 추가하는 방법에는 두 가지가 있습니다.

  • 서비스 애플리케이션의 서비스 호스트 또는 클라이언트 애플리케이션의 채널 팩터리를 열기 전에 Behaviors 속성에 사용자 지정 엔드포인트 동작을 프로그래밍 방식으로 추가합니다.

  • 애플리케이션 구성 파일을 사용하여 동작을 구성합니다. 자세한 내용은 behaviorExtensions를 참조<하세요>.

의도한 IEndpointBehavior 서비스 사용자 지정 작업을 수행하려면 메서드가 호출될 때 ICommunicationObject.Open 발생하는 서비스 런타임을 생성하기 전에 속성에 개체를 System.ServiceModel.ServiceHost추가 ServiceEndpoint.Behaviors 해야 합니다. 클라이언트 사용자 지정 작업을 수행하려면 메서드 또는 메서드를 IEndpointBehavior 호출하기 ServiceEndpoint.Behaviors 전에 속성에 ChannelFactory<TChannel>개체를 ChannelFactory<TChannel>.CreateChannel ICommunicationObject.Open 추가해야 합니다.

메서드

AddBindingParameters(ServiceEndpoint, BindingParameterCollection)

런타임에 바인딩에 데이터를 전달하여 사용자 지정 동작을 지원하려면 구현합니다.

ApplyClientBehavior(ServiceEndpoint, ClientRuntime)

엔드포인트에 대해 클라이언트의 수정이나 확장을 구현합니다.

ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher)

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

Validate(ServiceEndpoint)

엔드포인트가 특정 용도의 기준을 충족하는지 확인하려면 구현합니다.

적용 대상