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 IDisposable
interface ICommunicationObject
interface IAsyncDisposable
type ClientBase<'Channel (requires 'Channel : null)> = class
interface ICommunicationObject
interface IDisposable
type ClientBase<'Channel (requires 'Channel : null)> = class
interface IDisposable
interface ICommunicationObject
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 的行为。
构造函数
属性
| 名称 | 说明 |
|---|---|
| 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) |