tags:

views:

144

answers:

2

What is a Channel Factory and why do you use it?

+2  A: 

ChannelFactory is used to programatically create a WCF service proxy.

Sky Sanders
Is it used outside the context of WCF services too?
Nevin Mathai
Not that I know of. Hard to imagine how a WCF proxy factory would be useful if not in the context of WCF..
Sky Sanders
+1: Sometimes RTFM really is the best answer.
Juliet
@Juliet, don't think it did not occur to me. Guess I am in a good mood. ;-)
Sky Sanders
+1  A: 

If you used Visual Studio's Add Service Reference, or the svcutil.exe tool, you probably won't ever see a ChannelFactory.

Basically, creating the client-side proxy for a WCF service is a two-step process:

  • create the appropriate ChannelFactory<T> for your specific service contract
  • given that channel factory, create the actual communication channel between the client and the service

If you do have control over both ends of the wire, and you can put your service and data contracts into a separate assembly, you can break apart this two step process and handle it manually:

  • create the ChannelFactory<IMyService> once, this is a fairly complex and time-consuming operation, so if ever possible, try to do this only when really necessary, and then cache the channel factory for later reuse

  • create the actual channel using the channel factory whenever you need to communicate with the server

It's a very specific construct for WCF services, so I don't think you'll ever use it outside the WCF scope.

marc_s