A factory that creates channels of different types that are used by clients to send messages to variously configured service endpoints.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
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.
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.
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.