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>

備註

無論是 的延伸或 的 ClientBase<TChannel>IClientChannel WCF 用戶端物件,都是由 Windows Communication Foundation (WCF) 用戶端應用程式使用,將方法呼叫轉換成輸出訊息,並將傳入訊息轉換成物件,並將其傳遞至用戶端方法的結果。

ClientRuntime 類別是一個擴充點,您可以在這個擴充點上加入會在所有作業之間攔截訊息以及擴充用戶端行為的擴充物件。 攔截物件可以處理特定合約中的所有訊息,只處理特定作業的訊息,執行自訂通道初始設定,以及實作其他的自訂用戶端應用程式行為。 如需用戶端架構的概觀,請參閱 WCF 用戶端架構。 如需用戶端程式設計的詳細資訊,請參閱 使用 WCF 用戶端存取服務。 如需自訂專案以及如何執行自訂的詳細資訊,請參閱 擴充用戶端

  • CallbackDispatchRuntime 屬性會傳回服務初始化回呼作業的分派執行階段物件。

  • OperationSelector 屬性會接受自訂作業選取器物件以控制用戶端訊息的路由。

  • ChannelInitializers 屬性可以用來加入通道初始設定式,以便檢查或修改用戶端通道。

  • InteractiveChannelInitializers 屬性可以用來顯示視覺化提示,讓使用者能在開啟通道之前選取認證。

  • Operations 屬性會取得 ClientOperation 物件的集合,而您可以在這些物件中加入自訂訊息攔截器,以提供該作業之訊息的專屬功能。

  • ManualAddressing 屬性允許應用程式關閉一些自動定址標頭,以便直接控制定址。

  • MaxFaultSize 屬性允許用戶端限制用戶端接受的錯誤訊息大小。

  • MessageInspectors 屬性會取得 IClientMessageInspector 物件的集合,而您可以在這些物件中針對所有經過用戶端之訊息加入自訂訊息攔截器。

  • UnhandledClientOperation 屬性會傳回傳入了未預期訊息的作業。

  • ValidateMustUnderstand 屬性會通知系統是否要確認已實際瞭解標示為 MustUnderstand 的 SOAP 標頭。

  • Via 屬性會設定在傳輸層之訊息的目的端值,以便支援媒介及其他案例。

此外,還有一些會擷取用戶端合約資訊的其他屬性:

如果用戶端是雙工用戶端,下列屬性還會擷取用戶端回呼 (Callback) 型別和執行階段:

屬性

CallbackClientType

取得或設定與雙工用戶端相關聯之回呼合約的型別。

CallbackDispatchRuntime

取得分派服務啟動的作業的分派執行階段。

ChannelInitializers

取得通道初始設定式物件的集合,這些物件是用於自訂與用戶端相關聯的通道。

ClientMessageInspectors

取得用來檢視或修改特定服務作業之訊息的訊息偵測器物件集合。

ClientOperations

取得用戶端作業物件的集合,這些物件是用來附加檢查或修改特定服務作業之訊息及行為的擴充物件。

ContractClientType

取得或設定與用戶端相關聯之合約的類型。

ContractName

取得與用戶端相關聯之合約的名稱。

ContractNamespace

取得與用戶端相關聯之合約的命名空間。

DispatchRuntime

表示類別的插入點,這些類別會針對用戶端應用程式處理的所有訊息,擴充 Windows Communication Foundation (WCF) 用戶端物件的功能。

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)

適用於