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 客户端访问服务

针对从此类派生的托管 C++ 用户的特别说明:

  • 将清理代码加入 (On)(Begin)Close(和/或 OnAbort)中,而不是加入析构函数中。

  • 避免使用析构函数:它们会导致编译器自动生成 IDisposable

  • 避免使用非引用成员:它们可能会导致编译器自动生成 IDisposable

  • 避免使用终结器;但如果包含一个终结器,则应该禁止显示生成警告并从 (On)(Begin)Close(和/或 OnAbort)调用 SuppressFinalize(Object) 和终结器本身,以便模拟自动生成的 IDisposable 行为。

构造函数

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() 方法的显式实现。

适用于