How to Generate Proxy for WCF Services? | WCF Interview Question

, ,
The proxy can be generated using Visual Studio by right clicking Reference and clicking on Add Service Reference. This brings up the Add Service Reference dialog box, where you need to supply the base address of the service (or a base address and a MEX URI) and the namespace to contain the proxy. 

Proxy can also be generated by using SvcUtil.exe command-line utility. We need to provide SvcUtil with the HTTP-GET address or the metadata exchange endpoint address and, optionally, with a proxy filename. The default proxy filename is output.cs but you can also use the /out switch to indicate a different name. 

SvcUtil http://localhost/MyService/MyService.svc /out:Proxy.cs 

When we are hosting in IIS and selecting a port other than port 80 (such as port 88), we must provide that port number as part of the base address: 

SvcUtil http://localhost:88/MyService/MyService.svc /out:Proxy.cs