방법: 매개 변수 검사 또는 수정
WCF(Windows Communication Foundation) 클라이언트 개체 또는 WCF 서비스에서 System.ServiceModel.Dispatcher.IParameterInspector 인터페이스를 구현한 다음 클라이언트 또는 서비스 런타임에 삽입하여 단일 작업의 들어오는 메시지나 나가는 메시지를 검사 또는 수정할 수 있습니다. 일반적으로 작업 동작을 사용하여 단일 작업에 매개 변수 검사자를 추가하지만, 다른 동작을 사용하여 더 넓은 범위의 런타임에 쉬운 액세스를 제공할 수도 있습니다. 자세한 내용은 클라이언트 확장 및 디스패처 확장을 참조하십시오.
매개 변수 검사 또는 수정
System.ServiceModel.Dispatcher.IParameterInspector 인터페이스를 구현합니다.
필요한 범위에 따라 System.ServiceModel.Description.IOperationBehavior, System.ServiceModel.Description.IEndpointBehavior, System.ServiceModel.Description.IServiceBehavior 또는 System.ServiceModel.Description.IContractBehavior를 구현하여 매개 변수 검사자를 System.ServiceModel.Dispatcher.ClientOperation.ParameterInspectors 또는 System.ServiceModel.Dispatcher.DispatchOperation.ParameterInspectors 속성에 추가합니다.
System.ServiceModel.ChannelFactory에서 System.ServiceModel.ClientBase.Open 또는 System.ServiceModel.ICommunicationObject.Open 메서드를 호출하기 전에 동작을 삽입합니다. 자세한 내용은 동작을 사용하여 런타임 구성 및 확장을 참조하십시오.
예제
다음 코드 예제는 아래 순서대로 나열되어 있습니다.
매개 변수 검사자 구현.
System.ServiceModel.Description.IOperationBehavior, System.ServiceModel.Description.IEndpointBehavior 및 System.ServiceModel.Description.IServiceBehavior를 사용하여 매개 변수 검사자를 삽입하는 동작 구현.
클라이언트 응용 프로그램에서 끝점 동작을 로드하고 실행하여 클라이언트에 매개 변수 검사자를 삽입하는 구성 파일.
#Region "IParameterInspector Members"
Public Sub AfterCall(ByVal operationName As String, ByVal outputs() As Object, ByVal returnValue As Object, _
ByVal correlationState As Object) Implements IParameterInspector.AfterCall
Console.WriteLine("IParameterInspector.AfterCall called for {0} with return value {1}.", _
operationName, returnValue.ToString())
End Sub
Public Function BeforeCall(ByVal operationName As String, ByVal inputs() As Object) As Object Implements _
IParameterInspector.BeforeCall
Console.WriteLine("IParameterInspector.BeforeCall called for {0}.", operationName)
Return Nothing
End Function
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.ServiceModel.Configuration
Imports System.ServiceModel.Description
Imports System.ServiceModel.Dispatcher
Imports System.Text
Namespace Microsoft.WCF.Documentation
Public Class InspectorInserter
Inherits BehaviorExtensionElement
Implements IServiceBehavior, IEndpointBehavior, IOperationBehavior
#Region "IServiceBehavior Members"
Public Sub AddBindingParameters(ByVal serviceDescription As ServiceDescription, _
ByVal serviceHostBase As ServiceHostBase, ByVal endpoints As _
System.Collections.ObjectModel.Collection(Of ServiceEndpoint), _
ByVal bindingParameters As BindingParameterCollection) Implements IServiceBehavior.AddBindingParameters
Return
End Sub
Public Sub ApplyDispatchBehavior(ByVal serviceDescription As ServiceDescription, _
ByVal serviceHostBase As ServiceHostBase) Implements _
IServiceBehavior.ApplyDispatchBehavior
For Each chDisp As ChannelDispatcher In serviceHostBase.ChannelDispatchers
For Each epDisp As EndpointDispatcher In chDisp.Endpoints
epDisp.DispatchRuntime.MessageInspectors.Add(New Inspector())
For Each op As DispatchOperation In epDisp.DispatchRuntime.Operations
op.ParameterInspectors.Add(New Inspector())
Next op
Next epDisp
Next chDisp
End Sub
Public Sub Validate(ByVal serviceDescription As ServiceDescription, ByVal serviceHostBase As ServiceHostBase) _
Implements IServiceBehavior.Validate
Return
End Sub
#End Region
#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
#End Region
#Region "IOperationBehavior Members"
Public Sub AddBindingParameters(ByVal operationDescription As OperationDescription, _
ByVal bindingParameters As BindingParameterCollection) Implements _
IOperationBehavior.AddBindingParameters
Return
End Sub
Public Sub ApplyClientBehavior(ByVal operationDescription As OperationDescription, ByVal _
clientOperation As ClientOperation) Implements IOperationBehavior.ApplyClientBehavior
clientOperation.ParameterInspectors.Add(New Inspector())
End Sub
Public Sub ApplyDispatchBehavior(ByVal operationDescription As OperationDescription, ByVal dispatchOperation As _
DispatchOperation) Implements IOperationBehavior.ApplyDispatchBehavior
dispatchOperation.ParameterInspectors.Add(New Inspector())
End Sub
Public Sub Validate(ByVal operationDescription As OperationDescription) Implements IOperationBehavior.Validate
Return
End Sub
#End Region
Public Overrides ReadOnly Property BehaviorType() As Type
Get
Return GetType(InspectorInserter)
End Get
End Property
Protected Overrides Function CreateBehavior() As Object
Return New InspectorInserter()
End Function
End Class
End Namespace
<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>