ClientBase<TChannel> 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供用來建立可呼叫服務之 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 ICommunicationObject
interface IDisposable
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 (和/或 OnAbort) 中,而不是解構函式中。
避免使用解構函式,因為它們會導致編譯器自動產生 IDisposable。
避免使用非參考成員,因為它們會導致編譯器自動產生 IDisposable。
避免使用完成項,但如果您要加入完成項,則應隱藏建置警告並從 (On)(Begin)Close (和/或 OnAbort) 呼叫 和完成項本身,以模擬原本可能自動產生的 行為。
建構函式
屬性
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> 物件從已建立狀態轉換為已開啟狀態。 |
OpenAsync() |
提供用來建立可呼叫服務之 Windows Communication Foundation (WCF) 用戶端物件的基底實作。 |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |
明確介面實作
擴充方法
CloseHelperAsync(ICommunicationObject, TimeSpan) |
提供用來建立可呼叫服務之 Windows Communication Foundation (WCF) 用戶端物件的基底實作。 |
OpenHelperAsync(ICommunicationObject, TimeSpan) |
提供用來建立可呼叫服務之 Windows Communication Foundation (WCF) 用戶端物件的基底實作。 |
ConfigureAwait(IAsyncDisposable, Boolean) |
設定如何執行從非同步可處置項目傳回的工作 await。 |
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應