ClientRuntime.MessageInspectors 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取客户端的消息检查器实现的集合。
public:
property System::Collections::Generic::SynchronizedCollection<System::ServiceModel::Dispatcher::IClientMessageInspector ^> ^ MessageInspectors { System::Collections::Generic::SynchronizedCollection<System::ServiceModel::Dispatcher::IClientMessageInspector ^> ^ get(); };
public System.Collections.Generic.SynchronizedCollection<System.ServiceModel.Dispatcher.IClientMessageInspector> MessageInspectors { get; }
member this.MessageInspectors : System.Collections.Generic.SynchronizedCollection<System.ServiceModel.Dispatcher.IClientMessageInspector>
Public ReadOnly Property MessageInspectors As SynchronizedCollection(Of IClientMessageInspector)
属性值
IClientMessageInspector 实现的集合。
示例
在下面的代码示例中,System.ServiceModel.Description.IEndpointBehavior 通过将 System.ServiceModel.Dispatcher.IClientMessageInspector 添加到 MessageInspectors 属性,从而将它插入到客户端运行时中。
#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>
注解
使用 MessageInspectors 属性可以附加自定义 IClientMessageInspector 实现,以检查或修改流过客户端的所有消息。