BindingElement.BuildChannelFactory<TChannel> Method (BindingContext)

 

Initializes a channel factory for producing channels of a specified type from the binding context.

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

public virtual IChannelFactory<TChannel> BuildChannelFactory<TChannel>(
	BindingContext context
)

Parameters

context
Type: System.ServiceModel.Channels.BindingContext

The BindingContext that provides context for the binding element.

Return Value

Type: System.ServiceModel.Channels.IChannelFactory<TChannel>

The IChannelFactory<TChannel> of type TChannel initialized from the context.

Type Parameters

TChannel

The type of channel the factory builds.

Exception Condition
ArgumentNullException

context is null.

CustomBinding binding = new CustomBinding();
HttpTransportBindingElement element = new HttpTransportBindingElement();
BindingParameterCollection parameters = new BindingParameterCollection();
BindingContext context = new BindingContext(binding, parameters);

IChannelFactory<IRequestChannel> factory = element.BuildChannelFactory<IRequestChannel>(context);
factory.Open();
EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
IRequestChannel channel = factory.CreateChannel(address);
channel.Open();
Message request = Message.CreateMessage(MessageVersion.Default, "hello");
Message reply = channel.Request(request);
Console.Out.WriteLine(reply.Headers.Action);
reply.Close();
channel.Close();
factory.Close();

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: