ClientBase<TChannel> ClientBase<TChannel> ClientBase<TChannel> ClientBase<TChannel> Class

定義

提供用來建立可呼叫服務之 Windows Communication Foundation (WCF) 用戶端物件的基底實作。Provides the base implementation used to create Windows Communication Foundation (WCF) client objects that can call services.

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

類型參數

TChannel

用來連接服務的通道。The channel to be used to connect to the service.

繼承
ClientBase<TChannel>ClientBase<TChannel>ClientBase<TChannel>ClientBase<TChannel>
衍生
實作

範例

下列程式碼範例示範System.servicemodel 中繼資料公用程式工具(Svcutil)如何擴充 @no__t 1 類別,以建立 WCF 用戶端類別。The following code example shows how the ServiceModel Metadata Utility Tool (Svcutil.exe) extends the ClientBase<TChannel> class to create a WCF client class.

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

備註

擴充 @no__t 0 類別,以建立可用來連接到服務的自訂 WCF 用戶端物件。Extend the ClientBase<TChannel> class to create a custom WCF client object that can be used to connect to a service. 一般而言,WCF 用戶端基類是由您代表您的工具(如「 System.servicemodel 中繼資料公用程式」工具(Svcutil .exe))擴充。Typically, the WCF client base class is extended by a tool such as the ServiceModel Metadata Utility Tool (Svcutil.exe) on your behalf. 如需範例,請參閱<範例>一節。For an example, see the Example section.

偏好將物件用於介面及 ClientBase<TChannel> 類別的開發人員可快速輕鬆使用 System.ServiceModel.ChannelFactory<TChannel> 類別。The ClientBase<TChannel> class can be used quickly and easily by developers who prefer objects to the use of the interfaces and the System.ServiceModel.ChannelFactory<TChannel> class. 在所有情況下,這個類別都會包裝或公開 System.ServiceModel.ChannelFactory<TChannel> 類別和 System.ServiceModel.IClientChannel 介面的方法與功能。In all cases this class wraps or exposes the methods and functionality of the System.ServiceModel.ChannelFactory<TChannel> class and the System.ServiceModel.IClientChannel interface.

如同使用 System.ServiceModel.ServiceHost 類別時,在進行任何呼叫或呼叫 Open 之前,您可建立類別並變更端點、通道處理站或安全性資訊。As when using the System.ServiceModel.ServiceHost class, you can create the class and modify the endpoint, channel factory, or security information prior to making any calls or calling Open. 如需詳細資訊,請參閱Wcf 用戶端總覽使用 Wcf 用戶端存取服務For more information, see WCF Client Overview and Accessing Services Using a WCF Client.

給衍生自此類別之 Managed C++ 使用者的特別說明:Special note for Managed C++ users deriving from this class:

  • 請將您的清除程式碼置於 (On)(Begin)Close (和/或 OnAbort) 中,而不是解構函式中。Put your clean-up code in (On)(Begin)Close (and/or OnAbort), not in a destructor.

  • 避免使用解構函式,因為它們會導致編譯器自動產生 IDisposableAvoid destructors: they cause the compiler to auto-generate IDisposable.

  • 避免使用非參考成員,因為它們會導致編譯器自動產生 IDisposableAvoid non-reference members: they can cause the compiler to auto-generate IDisposable.

  • 避免使用完成項,但如果您要加入完成項,則應隱藏建置警告並從 (On)(Begin)Close (和/或 OnAbort) 呼叫 SuppressFinalize(Object)IDisposable和完成項本身,以模擬原本可能自動產生的 行為。Avoid finalizers; but if you include one, you should suppress the build warning and call SuppressFinalize(Object) and the finalizer itself from (On)(Begin)Close (and/or OnAbort) to emulate what would have been the auto-generated IDisposable behavior.

建構函式

ClientBase<TChannel>() ClientBase<TChannel>() ClientBase<TChannel>() ClientBase<TChannel>()

使用應用程式組態檔中的預設目標端點,初始化 ClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class using the default target endpoint from the application configuration file.

ClientBase<TChannel>(Binding, EndpointAddress) ClientBase<TChannel>(Binding, EndpointAddress) ClientBase<TChannel>(Binding, EndpointAddress) ClientBase<TChannel>(Binding, EndpointAddress)

使用指定的繫結與目標位址,初始化 ClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class using the specified binding and target address.

ClientBase<TChannel>(InstanceContext) ClientBase<TChannel>(InstanceContext) ClientBase<TChannel>(InstanceContext) ClientBase<TChannel>(InstanceContext)

在雙工對話中,使用 ClientBase<TChannel> 做為回呼物件來初始化 callbackInstance 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class using the callbackInstance as the callback object in a duplex conversation.

ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress) ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress) ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress) ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

初始化 ClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class.

ClientBase<TChannel>(InstanceContext, ServiceEndpoint) ClientBase<TChannel>(InstanceContext, ServiceEndpoint) ClientBase<TChannel>(InstanceContext, ServiceEndpoint) ClientBase<TChannel>(InstanceContext, ServiceEndpoint)

使用指定的 ClientBase<TChannel>InstanceContext 物件,初始化 ServiceEndpoint 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class using the specified InstanceContext and ServiceEndpoint objects.

ClientBase<TChannel>(InstanceContext, String) ClientBase<TChannel>(InstanceContext, String) ClientBase<TChannel>(InstanceContext, String) ClientBase<TChannel>(InstanceContext, String)

使用指定的回呼服務與端點組態資訊,初始化 ClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class using the specified callback service and endpoint configuration information.

ClientBase<TChannel>(InstanceContext, String, EndpointAddress) ClientBase<TChannel>(InstanceContext, String, EndpointAddress) ClientBase<TChannel>(InstanceContext, String, EndpointAddress) ClientBase<TChannel>(InstanceContext, String, EndpointAddress)

初始化 ClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class.

ClientBase<TChannel>(InstanceContext, String, String) ClientBase<TChannel>(InstanceContext, String, String) ClientBase<TChannel>(InstanceContext, String, String) ClientBase<TChannel>(InstanceContext, String, String)

初始化 ClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class.

ClientBase<TChannel>(ServiceEndpoint) ClientBase<TChannel>(ServiceEndpoint) ClientBase<TChannel>(ServiceEndpoint) ClientBase<TChannel>(ServiceEndpoint)

使用指定的 ServiceEndpoint,初始化 ClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class using the specified ServiceEndpoint.

ClientBase<TChannel>(String) ClientBase<TChannel>(String) ClientBase<TChannel>(String) ClientBase<TChannel>(String)

使用由 ClientBase<TChannel> 在應用程式組態檔中指定的組態資訊,初始化 endpointConfigurationName 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class using the configuration information specified in the application configuration file by endpointConfigurationName.

ClientBase<TChannel>(String, EndpointAddress) ClientBase<TChannel>(String, EndpointAddress) ClientBase<TChannel>(String, EndpointAddress) ClientBase<TChannel>(String, EndpointAddress)

使用指定的目標位址與端點資訊,初始化 ClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class using the specified target address and endpoint information.

ClientBase<TChannel>(String, String) ClientBase<TChannel>(String, String) ClientBase<TChannel>(String, String) ClientBase<TChannel>(String, String)

初始化 ClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the ClientBase<TChannel> class.

屬性

CacheSetting CacheSetting CacheSetting CacheSetting

取得或設定快取設定。Gets or sets the cache setting.

Channel Channel Channel Channel

取得用來傳送訊息至多種不同設定服務端點的內部通道。Gets the inner channel used to send messages to variously configured service endpoints.

ChannelFactory ChannelFactory ChannelFactory ChannelFactory

取得基礎 ChannelFactory<TChannel> 物件。Gets the underlying ChannelFactory<TChannel> object.

ClientCredentials ClientCredentials ClientCredentials ClientCredentials

取得用來呼叫作業的用戶端認證。Gets the client credentials used to call an operation.

Endpoint Endpoint Endpoint Endpoint

取得 WCF 用戶端可連線之服務的目標端點。Gets the target endpoint for the service to which the WCF client can connect.

InnerChannel InnerChannel InnerChannel InnerChannel

取得基礎 IClientChannel 實作。Gets the underlying IClientChannel implementation.

State State State State

取得 ClientBase<TChannel> 物件的目前狀態。Gets the current state of the ClientBase<TChannel> object.

方法

Abort() Abort() Abort() Abort()

導致 ClientBase<TChannel> 物件從目前的狀態立即轉換為已關閉狀態。Causes the ClientBase<TChannel> object to transition immediately from its current state into the closed state.

Close() Close() Close() Close()

導致 ClientBase<TChannel> 物件從目前的狀態轉換為已關閉狀態。Causes the ClientBase<TChannel> object to transition from its current state into the closed state.

CreateChannel() CreateChannel() CreateChannel() CreateChannel()

傳回服務的新通道。Returns a new channel to the service.

DisplayInitializationUI() DisplayInitializationUI() DisplayInitializationUI() DisplayInitializationUI()

如果需要使用者介面來初始化通道才能使用,會先指示該通道顯示使用者介面。Instructs the inner channel to display a user interface if one is required to initialize the channel prior to using it.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetDefaultValueForInitialization<T>() GetDefaultValueForInitialization<T>() GetDefaultValueForInitialization<T>() GetDefaultValueForInitialization<T>()

以 C# 複製預設關鍵字的行為。Replicates the behavior of the default keyword in C#.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
InvokeAsync(ClientBase<TChannel>, Object[], ClientBase<TChannel>, SendOrPostCallback, Object) InvokeAsync(ClientBase<TChannel>, Object[], ClientBase<TChannel>, SendOrPostCallback, Object) InvokeAsync(ClientBase<TChannel>, Object[], ClientBase<TChannel>, SendOrPostCallback, Object) InvokeAsync(ClientBase<TChannel>, Object[], ClientBase<TChannel>, SendOrPostCallback, Object)

提供實作事件架構非同步模式的支援。Provides support for implementing the event-based asynchronous pattern. 如需此模式的詳細資訊,請參閱事件架構非同步模式概觀For more information about this pattern, see Event-based Asynchronous Pattern Overview.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
Open() Open() Open() Open()

導致 ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態。Causes the ClientBase<TChannel> object to transition from the created state into the opened state.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

ICommunicationObject.BeginClose(AsyncCallback, Object) ICommunicationObject.BeginClose(AsyncCallback, Object) ICommunicationObject.BeginClose(AsyncCallback, Object) ICommunicationObject.BeginClose(AsyncCallback, Object)

開始非同步作業以關閉 ClientBase<TChannel>Begins an asynchronous operation to close the ClientBase<TChannel>.

ICommunicationObject.BeginClose(TimeSpan, AsyncCallback, Object) ICommunicationObject.BeginClose(TimeSpan, AsyncCallback, Object) ICommunicationObject.BeginClose(TimeSpan, AsyncCallback, Object) ICommunicationObject.BeginClose(TimeSpan, AsyncCallback, Object)

開始非同步作業以關閉具有指定逾時的 ClientBase<TChannel>Begins an asynchronous operation to close the ClientBase<TChannel> with a specified timeout.

ICommunicationObject.BeginOpen(AsyncCallback, Object) ICommunicationObject.BeginOpen(AsyncCallback, Object) ICommunicationObject.BeginOpen(AsyncCallback, Object) ICommunicationObject.BeginOpen(AsyncCallback, Object)

開始非同步作業以開啟 ClientBase<TChannel> 物件。Begins an asynchronous operation to open the ClientBase<TChannel> object.

ICommunicationObject.BeginOpen(TimeSpan, AsyncCallback, Object) ICommunicationObject.BeginOpen(TimeSpan, AsyncCallback, Object) ICommunicationObject.BeginOpen(TimeSpan, AsyncCallback, Object) ICommunicationObject.BeginOpen(TimeSpan, AsyncCallback, Object)

開始非同步作業以在指定的時間間隔內開啟 ClientBase<TChannel> 物件。Begins an asynchronous operation to open the ClientBase<TChannel> object within a specified interval of time.

ICommunicationObject.Close() ICommunicationObject.Close() ICommunicationObject.Close() ICommunicationObject.Close()
ICommunicationObject.Close(TimeSpan) ICommunicationObject.Close(TimeSpan) ICommunicationObject.Close(TimeSpan) ICommunicationObject.Close(TimeSpan)

導致 ClientBase<TChannel> 物件從目前的狀態轉換為已關閉狀態。Causes the ClientBase<TChannel> object to transition from its current state into the closed state.

ICommunicationObject.Closed ICommunicationObject.Closed ICommunicationObject.Closed ICommunicationObject.Closed

ClientBase<TChannel> 物件從目前狀態轉換為已關閉狀態時叫用的事件處理常式。The event handler that is invoked when the ClientBase<TChannel> object has transitioned from its current state to the closed state.

ICommunicationObject.Closing ICommunicationObject.Closing ICommunicationObject.Closing ICommunicationObject.Closing

ClientBase<TChannel> 物件從目前狀態轉換為已關閉狀態時叫用的事件處理常式。The event handler that is invoked when the ClientBase<TChannel> object transitions from its current state to the closed state.

ICommunicationObject.EndClose(IAsyncResult) ICommunicationObject.EndClose(IAsyncResult) ICommunicationObject.EndClose(IAsyncResult) ICommunicationObject.EndClose(IAsyncResult)

完成非同步作業以關閉 ClientBase<TChannel> 物件。Completes an asynchronous operation to close the ClientBase<TChannel> object.

ICommunicationObject.EndOpen(IAsyncResult) ICommunicationObject.EndOpen(IAsyncResult) ICommunicationObject.EndOpen(IAsyncResult) ICommunicationObject.EndOpen(IAsyncResult)

完成非同步作業以開啟 ClientBase<TChannel> 物件。Completes an asynchronous operation to open the ClientBase<TChannel> object.

ICommunicationObject.Faulted ICommunicationObject.Faulted ICommunicationObject.Faulted ICommunicationObject.Faulted

當針對 ClientBase<TChannel> 物件執行作業發生錯誤時叫用的事件處理常式。The event handler that is invoked when a fault occurs while performing an operation on the ClientBase<TChannel> object.

ICommunicationObject.Open() ICommunicationObject.Open() ICommunicationObject.Open() ICommunicationObject.Open()
ICommunicationObject.Open(TimeSpan) ICommunicationObject.Open(TimeSpan) ICommunicationObject.Open(TimeSpan) ICommunicationObject.Open(TimeSpan)

在指定時間間隔內,導致 ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態。Causes the ClientBase<TChannel> object to transition from the created state into the opened state within a specified interval of time.

ICommunicationObject.Opened ICommunicationObject.Opened ICommunicationObject.Opened ICommunicationObject.Opened

ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態時叫用的事件處理常式。The event handler that is invoked when the ClientBase<TChannel> object transitions from the created state to the opened state.

ICommunicationObject.Opening ICommunicationObject.Opening ICommunicationObject.Opening ICommunicationObject.Opening

ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態時叫用的事件處理常式。The event handler that is invoked when the ClientBase<TChannel> object transitions from the created state to the opened state.

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

Dispose() 方法的明確實作。Explicit implementation of the Dispose() method.

適用於