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>
派生
实现

示例

下面的代码示例演示如何ServiceModel Metadata Utility Tool (Svcutil.exe)扩展了ClientBase<TChannel>类,以创建 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

注解

扩展ClientBase<TChannel>类,以创建可用于连接到服务的自定义 WCF 客户端对象。Extend the ClientBase<TChannel> class to create a custom WCF client object that can be used to connect to a service. 通常情况下,WCF 客户端基类可通过扩展工具如ServiceModel Metadata Utility Tool (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 Client Overview使用 WCF 客户端访问服务For more information, see WCF Client Overview and Accessing Services Using a WCF Client.

针对从此类派生的托管 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 的浅表副本。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.

适用于