Dot Net For All

Using and Generating WCF Proxy class

In this article I will discuss about the WCF proxy class. Basically this article will include what is a WCF proxy class and ways to generate it on the client. In my previous articles I have discussed about the WCF contracts and creating a WCF service from scratchI will use C# language for this article.

WCF Proxy Class

Below are the definition of the proxy class and important points about it.

WCF proxy is a layer between Client and service. To access the services and for hiding the complexities of the services from the client we put this class.

This is the layer that extract all the low level communication that is necessary to establish a connection with the service layer which is on another machine. It helps in hand shaking and taking care of security , serialization and de serialization. Client only needs to know about certain operations.

Important points about WCF proxy class

Consuming the service

Ways To Create a Proxy Class

There are three ways by which we can generate a WCF proxy class for the client to consume. I will discuss them one by one.

  1. Inheriting a class from ClientBase<T> – As shown in one of my article here where I am creating the proxy by inheriting from the ClientBase<T> generic class.
  2. Using svcutil.exe – I will use the service from my previous article . You can download the  service project from hereIn this project I am self hosting the service in console application. To use the service from the svcutil.exe I should enable the metadata exchange in App.config of host project. The code for the change is as shown below figure.
                                  Fig: Enabling metadata Exchange

    Now to generate the proxy class we have to call the service from command prompt as shown in the below figure.

                                      Fig: Generating proxy using svutil.exe

  3. By Adding Service Reference – We can add a service reference as shown in the below figure. Right click in the client project > Add > Service Reference.

    Fig: Adding WCF proxy using reference

Conclusion:

In this article I discussed about the WCF proxy class. I have also added ways by which we can generate proxy class in WCF.

Top career enhancing courses you can't miss

My Learning Resource

Excel your system design interview