System.ServiceModel Namespa ...


.NET Framework Class Library
ChannelFactory<(Of <(TChannel>)>) Class

A factory that creates channels of different types that are used by clients to send messages to variously configured service endpoints.

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

Visual Basic (Declaration)
Public Class ChannelFactory(Of TChannel) _
    Inherits ChannelFactory _
    Implements IChannelFactory(Of TChannel), IChannelFactory,  _
    ICommunicationObject
Visual Basic (Usage)
Dim instance As ChannelFactory(Of TChannel)
C#
public class ChannelFactory<TChannel> : ChannelFactory, 
    IChannelFactory<TChannel>, IChannelFactory, ICommunicationObject
Visual C++
generic<typename TChannel>
public ref class ChannelFactory : public ChannelFactory, 
    IChannelFactory<TChannel>, IChannelFactory, ICommunicationObject
JScript
JScript does not support generic types or methods.

Type Parameters

TChannel

The type of channel produced by the channel factory. This type must be either IOutputChannel or IRequestChannel.

Remarks

This generic class enables more advanced scenarios where there is a requirement to create a channel factory that can be used to create more than one type of channel.

When adding behaviors programmatically, the behavior is added to the appropriate Behaviors property on the ChannelFactory prior to the creation of any channel. See the example section for a code sample.

Frequently client or calling applications (for example, middle-tier applications are client applications, too) using this type also have complex state management needs as well as performance needs. For more information about these scenarios, please see Middle-Tier Client Applications.

Examples

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

C#
           BasicHttpBinding binding = new BasicHttpBinding();
           EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");

           ChannelFactory<IRequestChannel> factory =
               new ChannelFactory<IRequestChannel>(binding, address);

           IRequestChannel channel = factory.CreateChannel();
           channel.Open();
           Message request = Message.CreateMessage(MessageVersion.Soap11, "hello");
           Message reply = channel.Request(request);
           Console.Out.WriteLine(reply.Headers.Action);
           reply.Close();
           channel.Close();
           factory.Close();

The following code example shows how to insert programmatically a client behavior prior to the creation of the channel object by the factory.

Inheritance Hierarchy

System..::.Object
  System.ServiceModel.Channels..::.CommunicationObject
    System.ServiceModel..::.ChannelFactory
      System.ServiceModel..::.ChannelFactory<(Of <(TChannel>)>)
        System.ServiceModel..::.DuplexChannelFactory<(Of <(TChannel>)>)
        System.ServiceModel.Web..::.WebChannelFactory<(Of <(TChannel>)>)
Thread Safety

This type is thread safe.

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, 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.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Tags :


Page view tracker