Click to Rate and Give Feedback
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
DuplexChannelFactory<(Of <(TChannel>)>) Class

Updated: November 2007

Provides the means to create and manage duplex channels of different types that are used by clients to send and receive messages to and from service endpoints.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

Visual Basic (Declaration)
Public Class DuplexChannelFactory(Of TChannel) _
    Inherits ChannelFactory(Of TChannel)
Visual Basic (Usage)
Dim instance As DuplexChannelFactory(Of TChannel)
C#
public class DuplexChannelFactory<TChannel> : ChannelFactory<TChannel>
Visual C++
generic<typename TChannel>
public ref class DuplexChannelFactory : public ChannelFactory<TChannel>
J#
J# supports the use of generic APIs, but not the declaration of new ones.
JScript
JScript does not support generic types or methods.

Type Parameters

TChannel

The type of channel produced by the channel factory.

A duplex channel allows clients and servers to communicate with each other independently so that either can initiate calls to the other. A duplex service can send messages to the client endpoint, providing event-like behavior. Duplex communication occurs when a client establishes a session with a service and provides the service with a channel on which the service can send messages back to the client. The various CreateChannel methods are used to create these duplex channels. The duplex message pattern is one of three message patterns available to Windows Communication Foundation (WCF) services. The other two message patterns are one-way and request-reply.

For a general discussion of duplex services that allow clients to connect back to the service, see Duplex Services. For an outline and discussion of the steps involved in writing a Windows Communication Foundation (WCF) client application using a channel factory, see How to: Use the ChannelFactory. For a procedure describing how to create a Windows Communication Foundation (WCF) client in a client class that implements the callback interface to access a service that uses a duplex messaging pattern, see How to: Access Services with a Duplex Contract.

The following sample shows how to create a channel factory and use it to create and manage channels.

C#
        // 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);
                }
            }

System..::.Object
  System.ServiceModel.Channels..::.CommunicationObject
    System.ServiceModel..::.ChannelFactory
      System.ServiceModel..::.ChannelFactory<(Of <(TChannel>)>)
        System.ServiceModel..::.DuplexChannelFactory<(Of <(TChannel>)>)
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows Vista, Windows XP SP2, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker