none
What is the advantage of ChannelFactory to use in WCF RRS feed

  • Question

  • few people add service reference and call the service and few people call service without service reference rather they create proxy at their end dynamically by ChannelFactory and call the service.

    many people said often there is advantage of using ChannelFactory but i got any write up for the advantages of ChannelFactory. so if anyone know all the advantage of using ChannelFactory then please share with me. thanks

    using System.ServiceModel;
    using System.ServiceModel.Description;
    
         var binding = new WebHttpBinding();
         var factory = new ChannelFactory<IMyServiceContract>(binding, new EndpointAddress("http://url:port"));
         factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
    
         var myService = factory.CreateChannel();
    
         myService.ServiceMethod();
    Friday, April 11, 2014 7:21 AM

Answers

  • Hi,

    The Channel Factory class is used to construct a channel between the client and server without creating a Proxy. In some of the cases in which your service is tightly bound with to the client application, we can use an interface DLL directly and with the help of a Channel Factory, call a method. The advantage of the Channel Factory route is that it gives you access method(s) that wouldn't be available if you use svcutil.exe.

    Channel Factory is also useful when you do not share more than just the service contract with a client. If you know that your entity will not change frequently than it is better to use a Channel Factory than a Proxy.

    Using the ChannelFactory<T> class is an easier alternative to making calls to the WCF services to the laborious process of generating proxies via the SvcUtil.exe tool every time a service contract changes. Channel Factory is a factory for creating service communication channels at runtime.
    ChannelFactory<T> takes a generic parameter of the service type (it must be a service contract interface) to create a channel. Because ChannelFactory only requires knowledge of the service contract, it makes good design sense to put service/data contracts in separate assemblies from service implementations. This way, you can safely distribute contract assemblies to third parties who wish to consume services, without the risk of disclosing their actual implementation.

    For more information, please try to refer to:
    http://blogs.msdn.com/b/juveriak/archive/2008/02/03/using-channels-vs-proxies-in-wcf.aspx .

    http://www.dotnet-tricks.com/Tutorial/wcf/YEV3280913-Difference-between-WCF-Proxy-and-Channel-Factory.html .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Mou_kolkata Thursday, April 17, 2014 8:13 AM
    Monday, April 14, 2014 5:05 AM
    Moderator
  • see this excellent link on this subject matter.

    hope this helps!

    • Marked as answer by Mou_kolkata Thursday, April 17, 2014 8:14 AM
    Monday, April 14, 2014 6:28 AM

All replies

  • Hi,

    The Channel Factory class is used to construct a channel between the client and server without creating a Proxy. In some of the cases in which your service is tightly bound with to the client application, we can use an interface DLL directly and with the help of a Channel Factory, call a method. The advantage of the Channel Factory route is that it gives you access method(s) that wouldn't be available if you use svcutil.exe.

    Channel Factory is also useful when you do not share more than just the service contract with a client. If you know that your entity will not change frequently than it is better to use a Channel Factory than a Proxy.

    Using the ChannelFactory<T> class is an easier alternative to making calls to the WCF services to the laborious process of generating proxies via the SvcUtil.exe tool every time a service contract changes. Channel Factory is a factory for creating service communication channels at runtime.
    ChannelFactory<T> takes a generic parameter of the service type (it must be a service contract interface) to create a channel. Because ChannelFactory only requires knowledge of the service contract, it makes good design sense to put service/data contracts in separate assemblies from service implementations. This way, you can safely distribute contract assemblies to third parties who wish to consume services, without the risk of disclosing their actual implementation.

    For more information, please try to refer to:
    http://blogs.msdn.com/b/juveriak/archive/2008/02/03/using-channels-vs-proxies-in-wcf.aspx .

    http://www.dotnet-tricks.com/Tutorial/wcf/YEV3280913-Difference-between-WCF-Proxy-and-Channel-Factory.html .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Mou_kolkata Thursday, April 17, 2014 8:13 AM
    Monday, April 14, 2014 5:05 AM
    Moderator
  • see this excellent link on this subject matter.

    hope this helps!

    • Marked as answer by Mou_kolkata Thursday, April 17, 2014 8:14 AM
    Monday, April 14, 2014 6:28 AM