ClientRuntime 类

定义

表示类的插入点,这些类可以扩展客户端应用程序处理的所有消息的 Windows Communication Foundation (WCF) 客户端对象的功能。

public ref class ClientRuntime sealed
public ref class ClientRuntime sealed : System::ServiceModel::Dispatcher::ClientRuntimeCompatBase
public sealed class ClientRuntime
public sealed class ClientRuntime : System.ServiceModel.Dispatcher.ClientRuntimeCompatBase
type ClientRuntime = class
type ClientRuntime = class
    inherit ClientRuntimeCompatBase
Public NotInheritable Class ClientRuntime
Public NotInheritable Class ClientRuntime
Inherits ClientRuntimeCompatBase
继承
ClientRuntime
继承

示例

在下面的代码示例中,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>

注解

WCF 客户端对象(无论是扩展还是扩展)ClientBase<TChannel>IClientChannel由 Windows Communication Foundation (WCF) 客户端应用程序使用,将方法调用转换为出站消息,并将传入消息转换为对象,并将其传递给客户端方法的结果。

ClientRuntime 类是一个扩展点,您可以将截获消息并在所有操作中扩展客户端行为的扩展对象添加到该扩展点。 截获对象可以在特定的约定中处理所有消息,仅处理特定操作的消息,执行自定义通道初始化,以及实现其他自定义客户端应用程序行为。 有关客户端体系结构的概述,请参阅 WCF 客户端体系结构。 有关客户端编程的详细信息,请参阅 使用 WCF 客户端访问服务。 有关自定义项以及如何执行自定义的详细信息,请参阅 扩展客户端

  • CallbackDispatchRuntime 属性返回服务启动的回调操作的调度运行时对象。

  • OperationSelector 属性接受使用自定义操作选择器对象来控制客户端消息的路由。

  • 使用 ChannelInitializers 属性可以添加检查或修改客户端通道的通道初始值设定项。

  • InteractiveChannelInitializers 属性可用于显示可视化提示,使用户可以在打开通道前选择凭据。

  • Operations 属性获取 ClientOperation 对象的集合,您可以将提供特定于该操作的消息的功能的自定义消息拦截器添加到该集合。

  • 使用 ManualAddressing 属性,应用程序可以关闭某些自动寻址标头来直接控制寻址。

  • 使用 MaxFaultSize 属性,客户端可以限制客户端接受的错误消息的大小。

  • MessageInspectors 属性获取 IClientMessageInspector 对象的集合,您可以将通过客户端的所有消息的自定义消息拦截器添加到这些对象。

  • UnhandledClientOperation 属性返回意外消息被传递到的操作。

  • ValidateMustUnderstand 属性通知系统它是否应确认标记为 MustUnderstand 的 SOAP 标头是否确实已被理解。

  • Via 属性设置传输级别的消息的目标的值,来支持中介以及其他方案。

另外,还有其他多个属性可以检索客户端协定信息:

如果客户端是双工客户端,以下属性还可以检索客户端回调类型以及运行时:

属性

CallbackClientType

获取或设置与双工客户端关联的回调协定的类型。

CallbackDispatchRuntime

获取调度服务启动的操作的调度运行时。

ChannelInitializers

获取通道初始值设定项对象的集合,这些对象用于自定义与客户端关联的通道。

ClientMessageInspectors

获取用于查看或修改特殊服务操作消息的消息检查对象的集合。

ClientOperations

获取用于关联扩展对象的客户操作对象和某种特殊服务操作行为的集合,其中的扩展对象检查和修改消息。

ContractClientType

获取或设置与客户端关联的协定的类型。

ContractName

获取与客户端关联的协定的名称。

ContractNamespace

获取与客户端关联的协定的命名空间。

InteractiveChannelInitializers

获取交互式信道初始化软件的集合。

ManualAddressing

获取或设置一个值,该值指示客户端是否将寻址标头添加到请求-回复消息。

MaxFaultSize

获取或设置错误的最大大小。

MessageInspectors

获取客户端的消息检查器实现的集合。

MessageVersionNoneFaultsEnabled

获取或设置一个值,该值指示是否设置 MessageVersionNoneFaultsEnabled 属性。

Operations

获取客户端的客户端操作的集合。

OperationSelector

获取或设置可用于选择 IClientOperationSelector 的一个 ClientOperation 实现。

UnhandledClientOperation

获取在 ClientOperation 集合中不具有相应的 Operations 的方法的客户端操作。

ValidateMustUnderstand

获取或设置一个值,该值指定是由系统还是由应用程序强制执行 SOAP MustUnderstand 标头处理。

Via

获取或设置用于通过客户端发送消息的传输地址。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于