How to generate WCF service with SvcUtil.exe

Skrch picture Skrch · Jun 2, 2014 · Viewed 104.8k times · Source

I am using SvcUtil.exe to generate IClassName.cs file from wsdl file and that is working fine. My problem is that I do not know how to generate ClassName.svc file using command arguments for SvcUtil.exe.

After running the SvcUtil.exe I would like to get WCF service like when you created from Visual Studio Wizard containing all classes *.svc, *.cs, and interface.

Thank You, Skrch

Answer

Basavaraj Kabuure picture Basavaraj Kabuure · Jun 3, 2014

First of all to generate proxy class we need to have our service up and running. So before using this utility make sure that your service is running without any issue.

After verifying the service status go to Visual Studio Command Prompt and run the following command.

svcutil http://localhost/MyService/ClassName.svc /Language=c#
/t:Code /out:ClassNameProxy.cs /config:ClassNameProxy.config

In above command you should replace the service URL ( http://localhost/MyService/Service1.svc) with the URL of your service. Since my services is developed in c#.net so I choose to generate the proxies in the same language by using /Language=c# flag.

/t:code will specify that the out put should be generated as code.

/out:ClassNameProxy.cs /config:ClassNameProxy.config parameters will tell the utility to name the files as specified in these parameter values. After you run the command, tool will generate the output file and config file.

After that just include the ClassNameProxy.cs file into your project and open the ClassNameProxy.config file and copy the entries to your web.config file. You may also need to update the ClassNameProxy.vb file and update the namespace as per the one that you are using in your project. After that you can easily reference the service in your code and call the operations.