本文整理匯總了C#中System.ServiceModel.DuplexChannelFactory<TChannel>類的典型用法代碼示例。如果您正苦於以下問題:C# DuplexChannelFactory<TChannel>類的具體用法?C# DuplexChannelFactory<TChannel>怎麽用?C# DuplexChannelFactory<TChannel>使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DuplexChannelFactory<TChannel>類屬於System.ServiceModel命名空間,在下文中一共展示了DuplexChannelFactory<TChannel>類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: InstanceContext
// 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);
}
}