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 客户端访问服务。
针对从此类派生的托管 C++ 用户的特别说明:
将清理代码加入 (On)(Begin)Close(和/或 OnAbort)中,而不是加入析构函数中。
避免使用析构函数:它们会导致编译器自动生成 IDisposable。
避免使用非引用成员:它们可能会导致编译器自动生成 IDisposable。
避免使用终结器;但如果包含一个终结器,则应该禁止显示生成警告并从 (On)(Begin)Close(和/或 OnAbort)调用 SuppressFinalize(Object) 和终结器本身,以便模拟自动生成的 IDisposable 行为。
构造函数
属性
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) |
配置如何执行从异步可处置项返回的任务的等待。 |
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈