gtestasker
gtestasker

Reputation: 81

How to specify type of binding (http or tcp) when using IChannelFactory<TChannel>? What is the default underlying binding?

I am fairly new to WCF and am trying to understand what default underlying binding is used when we use IChannelFactory to create a channel. We have 2 method signatures to create channels with IChannelFactory but none of them have a parameter that take the type of binding for the channel. CreateChannel(EndpointAddress) and CreateChannel(EndpointAddress, Uri) are the 2 methods that I can see.

So what is the default binding used when we create a channel using the interface and if I need to change the default binding how can I do it? Many thanks in advance!

Upvotes: 0

Views: 405

Answers (1)

Colin Bull
Colin Bull

Reputation: 969

The ChannelFactory<T> constructor takes the binding as a parameter. So, you can do something like this

BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new 
EndpointAddress("http://localhost:8000/ChannelApp");

ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>(binding, address);

IRequestChannel channel = factory.CreateChannel();

This sample was taken from the class reference at WCF Channel Factory

Upvotes: 1

Related Questions