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

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

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

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

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

  • 避免终结器;但是,如果包含生成警告,则应禁止生成警告并调用 SuppressFinalize(Object) 和终结器本身(On)(Begin)Close(和/或 OnAbort)来模拟自动生成 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)

配置如何执行从异步可释放项返回的任务的 await。

适用于