HI WELCOME TO SIRIS

Difference between WCF Proxy and Channel Factory

There are two ways : Proxy and Channel Factory; to create a WCF Client or calling a WCF Service. In this article, I am going to expose the difference between Proxy and Channel Factory.
  1. WCF Proxy

    A WCF proxy is a CLR class that exposes the service contract. A Service proxy class has the service contract operations and some additional operations for managing the proxy life cycle and the connection to the service.
    There are two ways to create a WCF proxy as given below:
    1. Using Visual Studio by adding service reference to the client application.
    2. Using SvcUtil.exe command-line utility.
  2. Channel Factory

    A channel factory creates channels of different types that are used by client to send messages to the service. ChannelFactory class is used with a known interface to create the channel. This approach is commonly used when you have access control to both the server and the client.
    1. WSHttpBinding binding = new WSHttpBinding();
    2. EndpointAddress endpoint = new EndpointAddress("http://localhost/WcfService/MyService.svc/ws");
    3.  
    4. ChannelFactory<IMyService>channelFactory = new ChannelFactory<IMyService>(binding,endpoint );
    5. IMyService channel = channelFactory.CreateChannel();
    6.  
    7. //calling service operation
    8. channel.DoWork();
    9.  
    10. //Close channel
    11. channelFactory.Close();

Difference between WCF Proxy and Channel Factory

Proxy
Channel Factory
Only requires the service URL to access the service.
Requires direct access to the assembly which contains the service contract i.e. must have information about service interface.
Simple and easy to understand
Not easy since channels are complex and network-related
Proxy is best when your service is used by several applications.
Channel Factory is best when your service is tightly bound to a single application
Proxy can be created by using Visual Studio or SVCUtil tool.
ChannelFactory class is used to create channel and for accessing the service.
What do you think?
I hope you will enjoy the tips while programming with WCF. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.