Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
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
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)
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.

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.

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.

This type is 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