A service proxy or simply proxy in WCF enables application(s) to interact with WCF Service by sending and receiving messages. It's basically a class that encapsulates service details i.e. service path, service implementation technology, platform and communication protocol etc. It contains all the methods of service contract (signature only, not the implementation). So, when the application interact the service through proxy, it gives the impression that it's communicating a local object.
We can create proxy for a service by using Visual Studio or SvcUtil.exe.
Generating proxy using Visual Studio is simple and straight forward.
->Right click References and choose "Add Service Reference".
->Provide base address of the service on "Add Service Reference" dialog box and click "Go" button. Service will be listed below.
->Provide namespace and click OK.
Visual studio will generate a proxy automatically.
We can generate proxy using svcutil.exe utility using command line. This utility requires few parameters like HTTP-GET address or the metadata exchange endpoint address and a proxy filename i.e. optional.
svcutil http://localhost/MyService/Service1.svc /out:MyServiceProxy.cs
If we are hosting the service at a different port (other than default for IIS which is 80), we need to provide port number in base address.
svcutil http://localhost:8080/MyService/Service1.svc /out:MyServiceProxy.cs