ChannelFactory<(Of <(TChannel>)>) Class Home
This page is specific to:.NET Framework Version:3.03.5Silverlight 34.0
.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

'Usage

Dim instance As ChannelFactory(Of TChannel)

'Declaration

Public Class ChannelFactory(Of TChannel) _
    Inherits ChannelFactory _
    Implements IChannelFactory(Of TChannel), IChannelFactory,  _
    ICommunicationObject

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.

           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

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View