wcfchannelfactory

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


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?


Solution

  • 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.