Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Channel Factory in .NET?

Tags:

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

like image 398
Nevin Mathai Avatar asked Mar 19 '10 17:03

Nevin Mathai


2 Answers

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.

like image 160
marc_s Avatar answered Jan 02 '23 22:01

marc_s


ChannelFactory class is used to construct a channel between the client and the service without the need of a proxy. In some cases, you may have a service that is tightly bound to the client application. In such a case, you can reference the Interface DLL directly and use ChannelFactory to call your methods using that.

I suggest you also go thru the difference between Proxy and Channel factory. this will help you in understanding of exact use of Channel Factory.

like image 37
Ashish Khandelwal Avatar answered Jan 03 '23 00:01

Ashish Khandelwal