다음을 통해 공유


IClientMessageInspector 인터페이스

정의

메시지를 보거나 수정하기 위해 MessageInspectors 컬렉션에 추가할 수 있는 메시지 검사자 개체를 정의합니다.

public interface class IClientMessageInspector
public interface IClientMessageInspector
type IClientMessageInspector = interface
Public Interface IClientMessageInspector

예제

다음 코드 예제에서는 구현이 호출 될 때 콘솔에 문자열을 쓰는 구현을 보여 줍니다.

#region IClientMessageInspector Members
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
  Console.WriteLine("IClientMessageInspector.AfterReceiveReply called.");
  Console.WriteLine("Message: {0}", reply.ToString());
}

public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
{
  Console.WriteLine("IClientMessageInspector.BeforeSendRequest called.");
  return null;
}
#Region "IClientMessageInspector Members"
    Public Sub AfterReceiveReply(ByRef reply As System.ServiceModel.Channels.Message, _
                       ByVal correlationState As Object) Implements IClientMessageInspector.AfterReceiveReply
        Console.WriteLine("IClientMessageInspector.AfterReceiveReply called.")
        Console.WriteLine("Message: {0}", reply.ToString())
    End Sub

    Public Function BeforeSendRequest(ByRef request As System.ServiceModel.Channels.Message, _
            ByVal channel As IClientChannel) As Object Implements IClientMessageInspector.BeforeSendRequest
        Console.WriteLine("IClientMessageInspector.BeforeSendRequest called.")
        Return Nothing
    End Function

다음 코드 예제에서는 클라이언트 엔드포인트에 System.ServiceModel.Description.IEndpointBehavior 클라이언트 메시지 검사기를 삽입 하는 방법을 보여 있습니다.

#region IEndpointBehavior Members
public void AddBindingParameters(
  ServiceEndpoint endpoint, BindingParameterCollection bindingParameters
) { return; }

public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
  clientRuntime.MessageInspectors.Add(new Inspector());
  foreach (ClientOperation op in clientRuntime.Operations)
    op.ParameterInspectors.Add(new Inspector());
}

public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
  endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new Inspector());
  foreach (DispatchOperation op in endpointDispatcher.DispatchRuntime.Operations)
    op.ParameterInspectors.Add(new Inspector());
}

public void Validate(ServiceEndpoint endpoint){ return; }
#Region "IEndpointBehavior Members"
    Public Sub AddBindingParameters(ByVal endpoint As ServiceEndpoint, ByVal bindingParameters _
                                    As BindingParameterCollection) Implements IEndpointBehavior.AddBindingParameters
        Return
    End Sub

    Public Sub ApplyClientBehavior(ByVal endpoint As ServiceEndpoint, ByVal clientRuntime As ClientRuntime) _
    Implements IEndpointBehavior.ApplyClientBehavior
        clientRuntime.MessageInspectors.Add(New Inspector())
        For Each op As ClientOperation In clientRuntime.Operations
            op.ParameterInspectors.Add(New Inspector())
        Next op
    End Sub

    Public Sub ApplyDispatchBehavior(ByVal endpoint As ServiceEndpoint, ByVal endpointDispatcher As  _
                                     EndpointDispatcher) Implements IEndpointBehavior.ApplyDispatchBehavior
        endpointDispatcher.DispatchRuntime.MessageInspectors.Add(New Inspector())
        For Each op As DispatchOperation In endpointDispatcher.DispatchRuntime.Operations
            op.ParameterInspectors.Add(New Inspector())
        Next op
    End Sub

Public Sub Validate(ByVal endpoint As ServiceEndpoint) Implements IEndpointBehavior.Validate
    Return
End Sub

마지막으로 다음 코드 예제에서는 특정 엔드포인트에서 엔드포인트 동작을 사용하도록 클라이언트 구성 파일을 수정하는 방법을 보여 있습니다.

  <client>
      <endpoint 
        address="http://localhost:8080/SampleService" 
        behaviorConfiguration="clientInspectorsAdded" 
        binding="wsHttpBinding"
        bindingConfiguration="WSHttpBinding_ISampleService" 
        contract="ISampleService"
        name="WSHttpBinding_ISampleService"
      >
      </endpoint>
  </client>
<behaviors>
  <endpointBehaviors>
    <behavior name="clientInspectorsAdded">
      <clientInterceptors />
    </behavior>
  </endpointBehaviors>
</behaviors>
<extensions>
  <behaviorExtensions>
    <add 
      name="clientInterceptors" 
      type="Microsoft.WCF.Documentation.InspectorInserter, HostApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
  />
  </behaviorExtensions>
</extensions>

설명

인터페이스를 IClientMessageInspector 구현하고 컬렉션에 MessageInspectors 추가하여 WCF 클라이언트 개체를 통과할 때 메시지를 검사하거나 수정합니다. 자세한 내용은 ClientRuntime를 참조하십시오.

메서드

AfterReceiveReply(Message, Object)

회신 메시지가 수신된 후 클라이언트 애플리케이션에 다시 전달되기 전에 메시지를 검사하거나 수정할 수 있습니다.

BeforeSendRequest(Message, IClientChannel)

요청 메시지가 서비스에 전달되기 전에 메시지를 검사하거나 수정할 수 있습니다.

적용 대상