What is a Channel Factory in .NET?
What is a Channel Factory and 开发者_StackOverflow中文版why do you use it?
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 reusecreate 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.
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.
精彩评论