次の例では、チャネル ファクトリを作成する方法、およびそれを使用してチャネルを作成および管理する方法を示しています。
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();
次のコード例は、チャネル オブジェクトの作成前に、ファクトリによってプログラムでクライアント動作が挿入される方法を示します。