共用方式為


ClientBase<TChannel> 類別

定義

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

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

類型參數

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 (and/或 OnAbort),而不是解構函式中。

  • 避免解構函式:它們會導致編譯程式自動產生 IDisposable

  • 避免非參考成員:它們可能會導致編譯程式自動產生 IDisposable

  • 避免完成項;但是,如果您包含一個,您應該隱藏組建警告,並從 (On)(Begin)Close (and/或 OnAbort) 呼叫 SuppressFinalize(Object) 和完成項本身,以模擬自動產生的 IDisposable 行為。

建構函式

ClientBase<TChannel>()

使用應用程式組態檔的預設目標端點,初始化 ClientBase<TChannel> 類別的新實例。

ClientBase<TChannel>(Binding, EndpointAddress)

使用指定的系結和目標位址,初始化 ClientBase<TChannel> 類別的新實例。

ClientBase<TChannel>(InstanceContext)

使用 callbackInstance 作為雙工交談中的回呼物件,初始化 ClientBase<TChannel> 類別的新實例。

ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

初始化 ClientBase<TChannel> 類別的新實例。

ClientBase<TChannel>(InstanceContext, ServiceEndpoint)

使用指定的 InstanceContextServiceEndpoint 物件,初始化 ClientBase<TChannel> 類別的新實例。

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)

使用應用程式組態檔中指定的組態資訊,endpointConfigurationName,初始化 ClientBase<TChannel> 類別的新實例。

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> 物件從目前狀態轉換成關閉狀態。

CloseAsync()

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

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)

明確介面實作

IAsyncDisposable.DisposeAsync()

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

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() 方法。

擴充方法

ConfigureAwait(IAsyncDisposable, Boolean)

設定如何執行從異步可處置專案傳回的工作等候。

適用於