Powered by Blogger.

Sunday, March 2, 2014

Generate WCF Proxy using SvcUtil.exe

Svcutil.exe is a command line tool that helps to generate proxy class in C#.Net.

Then in the address bar give the address of the WCF service and click on Go.

Also you can check out:

- Get database server name in sql server 2008

- How to get distinct data from tables in sql server 2008?

- stored procedure to update record in sql server 2008


Optionally you can change the Namespace and click on Ok. Now you can access your WCF service.But what will happen if you are going to call that WCF in the production environment where there will be no Visual studio, you can not go for the above (Add Service Reference approach). Here it comes the SvcUtil.exe. To use that go to Start -> All Programs -> Microsoft Visual Studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt (2010). Then type

svcutil /language:cs /out:generatedproxy.cs /config:app.config
svcutil /language:cs /out:generatedproxy.cs /config:app.config

generatedproxy: It is the class name, you can provide any name.
language:cs: This is to select the language, for Vb.Net you can type language:VB
After this SvcUtil will generate 2 files one with the class name you have provided above and other is the app.config file.

The location of the files are:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\generatedproxy.cs
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\app.config
You can copy the generatedproxy.cs class file and app.config file and paste in the project directory. But If you are calling the WCF service inside a Web Site or Web Application, then you must have a web.config file. Then copy from <system.serviceModel> to </system.serviceModel> and paste it in the web.config before </configuration>.

Now you can create a object of the proxy class and use that.