How does ChannelFactory (WCF/C#) use an Interface as a type?

254 Views Asked by At

Looking at creating Channels explicitly in WCF, you do this:

IService channel = new ChannelFactory<IService>(binding, address).CreateChannel();

Why am I allowed to 'type' the channel factory as an interface? I know that the IService interface has to be decorated to allow this. what is ChannelFactory doing behind the scenes to allow this?

1

There are 1 best solutions below

2
tomasr On BEST ANSWER

Internally, ChannelFactory<TChannel> creates an object of type ServiceChannelProxy, which derives from System.Runtime.Remoting.Proxies.RealProxy, allowing it to create a transparent proxy over the TChannel interface.