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) | 
        	
显式接口实现
| IAsyncDisposable.DisposeAsync() | 
		 提供创建和管理不同类型的双工通道的方法,这些通道由客户端用来向/从服务终结点发送和接收消息。 (继承自 ChannelFactory) | 
        	
| IDisposable.Dispose() | 
		 关闭当前通道工厂。 (继承自 ChannelFactory) | 
        	
扩展方法
| ConfigureAwait(IAsyncDisposable, Boolean) | 
		 配置如何执行从异步可释放项返回的任务的 await。  |