Year End Sale: Get Upto 40% OFF on Live Training! Offer Ending in
D
H
M
S
Get Now
Difference between WCF Proxy and Channel Factory

Difference between WCF Proxy and Channel Factory

26 Aug 2022
Intermediate
88.8K Views
2 min read
Learn with an interactive course and practical hands-on labs

.NET Microservices Course

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.

    WSHttpBinding binding = new WSHttpBinding();
    EndpointAddress endpoint = new EndpointAddress("http://localhost/WcfService/MyService.svc/ws");
    
    ChannelFactory<IMyService>channelFactory = new ChannelFactory<IMyService>(binding,endpoint );
    IMyService channel = channelFactory.CreateChannel();
    
    //calling service operation
    channel.DoWork();
    
    //Close channel
    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.

Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at ScholarHat)

Shailendra Chauhan, Founder and CEO of ScholarHat by DotNetTricks, is a renowned expert in System Design, Software Architecture, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development. His skill set extends into emerging fields like Data Science, Python, Azure AI/ML, and Generative AI, making him a well-rounded expert who bridges traditional development frameworks with cutting-edge advancements. Recognized as a Microsoft Most Valuable Professional (MVP) for an impressive 9 consecutive years (2016–2024), he has consistently demonstrated excellence in delivering impactful solutions and inspiring learners.

Shailendra’s unique, hands-on training programs and bestselling books have empowered thousands of professionals to excel in their careers and crack tough interviews. A visionary leader, he continues to revolutionize technology education with his innovative approach.
Accept cookies & close this