DuplexChannelFactory<TChannel> 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供创建和管理不同类型的双工通道的方式,客户端使用这些通道在服务终结点发送和接收消息。
generic <typename TChannel>
public ref class DuplexChannelFactory : System::ServiceModel::ChannelFactory<TChannel>
public class DuplexChannelFactory<TChannel> : System.ServiceModel.ChannelFactory<TChannel>
type DuplexChannelFactory<'Channel> = class
inherit ChannelFactory<'Channel>
Public Class DuplexChannelFactory(Of TChannel)
Inherits ChannelFactory(Of TChannel)
类型参数
- TChannel
由通道工厂生成的通道类型。
- 继承
- 派生
示例
下面的示例演示如何创建通道工厂并用它来创建和管理通道。
// Construct InstanceContext to handle messages on the callback interface.
// An instance of ChatApp is created and passed to the InstanceContext.
InstanceContext site = new InstanceContext(new ChatApp());
// Create the participant with the given endpoint configuration.
// Each participant opens a duplex channel to the mesh.
// Participant is an instance of the chat application that has opened a channel to the mesh.
using (DuplexChannelFactory<IChatChannel> cf =
new DuplexChannelFactory<IChatChannel>(site,"ChatEndpoint"))
{
X509Certificate2 issuer = GetCertificate(
StoreName.CertificateAuthority,
StoreLocation.CurrentUser, "CN=" + issuerName,
X509FindType.FindBySubjectDistinguishedName);
cf.Credentials.Peer.Certificate =
GetCertificate(StoreName.My,
StoreLocation.CurrentUser,
"CN=" + member,
X509FindType.FindBySubjectDistinguishedName);
cf.Credentials.Peer.PeerAuthentication.CertificateValidationMode =
X509CertificateValidationMode.Custom;
cf.Credentials.Peer.PeerAuthentication.CustomCertificateValidator =
new IssuerBasedValidator();
using (IChatChannel participant = cf.CreateChannel())
{
// Retrieve the PeerNode associated with the participant and register for online/offline events.
// PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes.
IOnlineStatus ostat = participant.GetProperty<IOnlineStatus>();
ostat.Online += new EventHandler(OnOnline);
ostat.Offline += new EventHandler(OnOffline);
Console.WriteLine("{0} is ready", member);
Console.WriteLine("Press <ENTER> to send the chat message.");
// Announce self to other participants.
participant.Join(member);
Console.ReadLine();
participant.Chat(member, "Hi there - I am chatting");
Console.WriteLine("Press <ENTER> to terminate this instance of chat.");
Console.ReadLine();
// Leave the mesh and close the client.
participant.Leave(member);
}
}
注解
双工通道使得客户端和服务器可以独立地相互通信,这样双方都可以启动对另一方的调用。 双工服务可以将消息发送至客户端终结点,从而提供类似事件的行为。 当客户端与服务建立会话并为服务提供可用来将消息发送回客户端的通道时,就会发生双工通信。 有多种不同的 CreateChannel 方法可用于创建这些双工通道。 双工消息模式是 Windows Communication Foundation (WCF) 服务可用的三种消息模式之一。 另外两种消息模式是单向模式和请求-答复模式。
有关允许客户端连接回服务的双工服务的一般讨论,请参阅 双工服务。 有关使用通道工厂编写 Windows Communication Foundation (WCF) 客户端应用程序所涉及的步骤的概述和讨论,请参阅 如何:使用 ChannelFactory。 有关如何在实现回调接口的客户端类中创建 Windows Communication Foundation (WCF) 客户端以访问使用双工消息传送模式的服务的过程,请参阅 如何:使用双工协定访问服务。
构造函数
属性
Credentials |
获取客户端在通过由工厂产生的通道与服务终结点进行通信时使用的凭据。 (继承自 ChannelFactory) |
DefaultCloseTimeout |
获取为完成关闭操作提供的默认时间间隔。 (继承自 ChannelFactory) |
DefaultOpenTimeout |
获取为完成打开操作提供的默认时间间隔。 (继承自 ChannelFactory) |
Endpoint |
获取由工厂产生的通道所要连接的服务终结点。 (继承自 ChannelFactory) |
IsDisposed |
获取一个值,该值指示通信对象是否已被释放。 (继承自 CommunicationObject) |
State |
获取指示通信对象当前状态的值。 (继承自 CommunicationObject) |
ThisLock |
获取在状态转换过程中保护类实例的相互排斥锁。 (继承自 CommunicationObject) |
方法
事件
Closed |
当通信对象转换到已关闭状态时发生。 (继承自 CommunicationObject) |
Closing |
当通信对象转换到正在关闭状态时发生。 (继承自 CommunicationObject) |
Faulted |
在通信对象转换到出错状态时发生。 (继承自 CommunicationObject) |
Opened |
当通信对象转换到已打开状态时发生。 (继承自 CommunicationObject) |
Opening |
当通信对象转换到正在打开状态时发生。 (继承自 CommunicationObject) |
显式接口实现
IAsyncCommunicationObject.CloseAsync(TimeSpan) |
提供创建和管理不同类型的双工通道的方式,客户端使用这些通道在服务终结点发送和接收消息。 (继承自 CommunicationObject) |
IAsyncCommunicationObject.OpenAsync(TimeSpan) |
提供创建和管理不同类型的双工通道的方式,客户端使用这些通道在服务终结点发送和接收消息。 (继承自 CommunicationObject) |
IAsyncDisposable.DisposeAsync() |
提供创建和管理不同类型的双工通道的方式,客户端使用这些通道在服务终结点发送和接收消息。 (继承自 ChannelFactory) |
IDisposable.Dispose() |
关闭当前的通道工厂。 (继承自 ChannelFactory) |
扩展方法
CloseHelperAsync(ICommunicationObject, TimeSpan) |
提供创建和管理不同类型的双工通道的方式,客户端使用这些通道在服务终结点发送和接收消息。 |
OpenHelperAsync(ICommunicationObject, TimeSpan) |
提供创建和管理不同类型的双工通道的方式,客户端使用这些通道在服务终结点发送和接收消息。 |
GetInternalCloseTimeout(CommunicationObject) |
提供创建和管理不同类型的双工通道的方式,客户端使用这些通道在服务终结点发送和接收消息。 |
ConfigureAwait(IAsyncDisposable, Boolean) |
配置如何执行从异步可处置项返回的任务的等待。 |
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈