ClientBase<TChannel> 類別

定義

提供用來建立可呼叫服務之 Windows Communication Foundation (WCF) 用戶端物件的基底實作。

generic <typename TChannel>
 where TChannel : classpublic ref class ClientBase abstract : IDisposable, System::ServiceModel::ICommunicationObject
generic <typename TChannel>
 where TChannel : classpublic ref class ClientBase abstract : System::ServiceModel::ICommunicationObject
public abstract class ClientBase<TChannel> : IDisposable, System.ServiceModel.ICommunicationObject where TChannel : class
public abstract class ClientBase<TChannel> : System.ServiceModel.ICommunicationObject where TChannel : class
type ClientBase<'Channel (requires 'Channel : null)> = class
    interface IDisposable
    interface ICommunicationObject
type ClientBase<'Channel (requires 'Channel : null)> = class
    interface ICommunicationObject
type ClientBase<'Channel (requires 'Channel : null)> = class
    interface ICommunicationObject
    interface IDisposable
Public MustInherit Class ClientBase(Of TChannel)
Implements ICommunicationObject, IDisposable
Public MustInherit Class ClientBase(Of TChannel)
Implements ICommunicationObject

類型參數

TChannel

用來連接服務的通道。

繼承
ClientBase<TChannel>
衍生
實作

範例

下列程式碼範例示範 ServiceModel 中繼資料公用程式工具 (Svcutil.exe) 如何擴充 ClientBase<TChannel> 類別來建立 WCF 用戶端類別。

public partial class SampleServiceClient : System.ServiceModel.ClientBase<ISampleService>, ISampleService
{

    public SampleServiceClient()
    {
    }

    public SampleServiceClient(string endpointConfigurationName) :
            base(endpointConfigurationName)
    {
    }

    public SampleServiceClient(string endpointConfigurationName, string remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public SampleServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public SampleServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
            base(binding, remoteAddress)
    {
    }

    public string SampleMethod(string msg)
    {
        return base.Channel.SampleMethod(msg);
    }
}
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")> _
Partial Public Class SampleServiceClient
    Inherits System.ServiceModel.ClientBase(Of ISampleService)
    Implements ISampleService

    Public Sub New()
    End Sub

    Public Sub New(ByVal endpointConfigurationName As String)
        MyBase.New(endpointConfigurationName)
    End Sub

    Public Sub New(ByVal endpointConfigurationName As String, ByVal remoteAddress As String)
        MyBase.New(endpointConfigurationName, remoteAddress)
    End Sub

    Public Sub New(ByVal endpointConfigurationName As String, _
                   ByVal remoteAddress As System.ServiceModel.EndpointAddress)
        MyBase.New(endpointConfigurationName, remoteAddress)
    End Sub

    Public Sub New(ByVal binding As System.ServiceModel.Channels.Binding, _
                   ByVal remoteAddress As System.ServiceModel.EndpointAddress)
        MyBase.New(binding, remoteAddress)
    End Sub

    Public Function SampleMethod(ByVal msg As String) As String Implements ISampleService.SampleMethod
        Return MyBase.Channel.SampleMethod(msg)
    End Function
End Class

備註

ClientBase<TChannel>擴充 類別,以建立可用來連線至服務的自訂 WCF 用戶端物件。 一般而言,WCF 用戶端基類是由 ServiceModel 中繼資料公用程式工具 (Svcutil.exe) 代表您擴充的工具。 如需範例,請參閱<範例>一節。

偏好將物件用於介面及 ClientBase<TChannel> 類別的開發人員可快速輕鬆使用 System.ServiceModel.ChannelFactory<TChannel> 類別。 在所有情況下,這個類別都會包裝或公開 System.ServiceModel.ChannelFactory<TChannel> 類別和 System.ServiceModel.IClientChannel 介面的方法與功能。

如同使用 System.ServiceModel.ServiceHost 類別時,在進行任何呼叫或呼叫 Open 之前,您可建立類別並變更端點、通道處理站或安全性資訊。 如需詳細資訊,請參閱 WCF 用戶端概觀 和使用 WCF 用戶端存取服務

給衍生自此類別之 Managed C++ 使用者的特別說明:

  • 請將您的清除程式碼置於 (On)(Begin)Close (和/或 OnAbort) 中,而不是解構函式中。

  • 避免使用解構函式,因為它們會導致編譯器自動產生 IDisposable

  • 避免使用非參考成員,因為它們會導致編譯器自動產生 IDisposable

  • 避免使用完成項,但如果您要加入完成項,則應隱藏建置警告並從 (On)(Begin)Close (和/或 OnAbort) 呼叫 和完成項本身,以模擬原本可能自動產生的 行為。

建構函式

ClientBase<TChannel>()

使用應用程式組態檔中的預設目標端點,初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(Binding, EndpointAddress)

使用指定的繫結與目標位址,初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(InstanceContext)

在雙工對話中,使用 ClientBase<TChannel> 做為回呼物件來初始化 callbackInstance 類別的新執行個體。

ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(InstanceContext, ServiceEndpoint)

使用指定的 ClientBase<TChannel>InstanceContext 物件,初始化 ServiceEndpoint 類別的新執行個體。

ClientBase<TChannel>(InstanceContext, String)

使用指定的回呼服務與端點組態資訊,初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(InstanceContext, String, EndpointAddress)

初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(InstanceContext, String, String)

初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(ServiceEndpoint)

使用指定的 ServiceEndpoint,初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(String)

使用由 ClientBase<TChannel> 在應用程式組態檔中指定的組態資訊,初始化 endpointConfigurationName 類別的新執行個體。

ClientBase<TChannel>(String, EndpointAddress)

使用指定的目標位址與端點資訊,初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(String, String)

初始化 ClientBase<TChannel> 類別的新執行個體。

屬性

CacheSetting

取得或設定快取設定。

Channel

取得用來傳送訊息至多種不同設定服務端點的內部通道。

ChannelFactory

取得基礎 ChannelFactory<TChannel> 物件。

ClientCredentials

取得用來呼叫作業的用戶端認證。

Endpoint

取得 WCF 用戶端可連線之服務的目標端點。

InnerChannel

取得基礎 IClientChannel 實作。

State

取得 ClientBase<TChannel> 物件的目前狀態。

方法

Abort()

導致 ClientBase<TChannel> 物件從目前的狀態立即轉換為已關閉狀態。

Close()

導致 ClientBase<TChannel> 物件從目前的狀態轉換為已關閉狀態。

CreateChannel()

傳回服務的新通道。

DisplayInitializationUI()

如果需要使用者介面來初始化通道才能使用,會先指示該通道顯示使用者介面。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetDefaultValueForInitialization<T>()

以 C# 複製預設關鍵字的行為。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
InvokeAsync(ClientBase<TChannel>.BeginOperationDelegate, Object[], ClientBase<TChannel>.EndOperationDelegate, SendOrPostCallback, Object)

提供實作事件架構非同步模式的支援。 如需此模式的詳細資訊,請參閱事件架構非同步模式概觀

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Open()

導致 ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

ICommunicationObject.BeginClose(AsyncCallback, Object)

開始非同步作業以關閉 ClientBase<TChannel>

ICommunicationObject.BeginClose(TimeSpan, AsyncCallback, Object)

開始非同步作業以關閉具有指定逾時的 ClientBase<TChannel>

ICommunicationObject.BeginOpen(AsyncCallback, Object)

開始非同步作業以開啟 ClientBase<TChannel> 物件。

ICommunicationObject.BeginOpen(TimeSpan, AsyncCallback, Object)

開始非同步作業以在指定的時間間隔內開啟 ClientBase<TChannel> 物件。

ICommunicationObject.Close()

導致通訊物件從目前的狀態轉換為已關閉狀態。

ICommunicationObject.Close(TimeSpan)

導致 ClientBase<TChannel> 物件從目前的狀態轉換為已關閉狀態。

ICommunicationObject.Closed

ClientBase<TChannel> 物件從目前狀態轉換為已關閉狀態時叫用的事件處理常式。

ICommunicationObject.Closing

ClientBase<TChannel> 物件從目前狀態轉換為已關閉狀態時叫用的事件處理常式。

ICommunicationObject.EndClose(IAsyncResult)

完成非同步作業以關閉 ClientBase<TChannel> 物件。

ICommunicationObject.EndOpen(IAsyncResult)

完成非同步作業以開啟 ClientBase<TChannel> 物件。

ICommunicationObject.Faulted

在針對 ClientBase<TChannel> 物件執行作業發生錯誤時叫用的事件處理常式。

ICommunicationObject.Open()

導致通訊物件從已建立狀態轉換為已開啟狀態。

ICommunicationObject.Open(TimeSpan)

在指定時間間隔內,導致 ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態。

ICommunicationObject.Opened

ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態時叫用的事件處理常式。

ICommunicationObject.Opening

ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態時叫用的事件處理常式。

IDisposable.Dispose()

Dispose() 方法的明確實作。

適用於