System.ServiceModel.Dispatcher.IClientMessageInspector를 구현하고 클라이언트 런타임에 삽입하여 들어오거나 보내는 메시지를 WCF에서 검사하거나 수정할 수 있습니다. 자세한 내용은 클라이언트 확장을 참조하십시오. 서비스의 해당 기능은 System.ServiceModel.Dispatcher.IDispatchMessageInspector입니다.
메시지를 검사하거나 수정하려면
System.ServiceModel.Dispatcher.IClientMessageInspector 인터페이스를 구현합니다.
클라이언트 메시지 검사자를 쉽게 삽입하려는 범위에 따라 System.ServiceModel.Description.IEndpointBehavior 또는 System.ServiceModel.Description.IContractBehavior를 구현합니다.
System.ServiceModel.ChannelFactory에서 System.ServiceModel.ClientBase.Open 또는 System.ServiceModel.ICommunicationObject.Open 메서드를 호출하여 동작을 삽입합니다. 자세한 내용은 동작을 사용하여 런타임 구성 및 확장을 참조하십시오.
예제
다음 코드 예제는 아래 순서대로 나열되어 있습니다.
클라이언트 검사자 구현.
검사자를 삽입하는 끝점 동작.
클라이언트 응용 프로그램에서 동작을 로드 및 실행하는 구성 파일.
#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
#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())
End Sub
Public Sub ApplyDispatchBehavior(ByVal endpoint As ServiceEndpoint, ByVal endpointDispatcher As EndpointDispatcher) Implements IEndpointBehavior.ApplyDispatchBehavior
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(New Inspector())
End Sub
Public Sub Validate(ByVal endpoint As ServiceEndpoint) Implements IEndpointBehavior.Validate
Return
End Sub
<client>
<endpoint
address="https://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>
참고 항목
참조
System.ServiceModel.Dispatcher.IClientMessageInspector
System.ServiceModel.Dispatcher.IDispatchMessageInspector