How to generate WCF service with SvcUtil.exe
Asked Answered
O

5

13

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

Osprey answered 2/6, 2014 at 15:11 Comment(1)
I don't believe SVCUITL is capable of doing that. When you add a reference through Visual Studio, it doesn't generate the .svc and service implmentation/contract (.cs and interface) files either.Pauly
S
23

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.

Sunday answered 3/6, 2014 at 12:48 Comment(3)
include reference devtoolbox.wordpress.com/2011/04/03/…Mellman
After running the SvcUtil.exe , got error when execute in command - An error occurred while making the HTTP request to xxx.fmcsa.dot.gov/myService.svc?wsdl. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.Literary
Include namespace parameter also by adding /n:"Microsoft.Samples.Certificate,Microsoft.Samples.Certificate" (the namespace string may vary)Jehias
O
19

Some examples from tool how it can be used

svcutil http://service/metadataEndpoint - Generate client code from a running service or online metadata documents.

svcutil *.wsdl *.xsd /language:C# - Generate client code from local metadata documents.

svcutil /dconly *.xsd /language:VB - Generate Data Contract types in VisualBasic from local schema documents.

svcutil /t:metadata http://service/metadataEndpoint - Download metadata documents from running services

svcutil myAssembly.dll - Generate metadata documents for Service Contracts and associated types in an assembly

svcutil myServiceHost.exe /serviceName:myServiceName - Generate metadata documents for a service, and all associated Service Contracts and data types in an assembly

svcutil myServiceHost.exe /dconly - Generate metadata documents for data types in an assembly

svcutil /validate /serviceName:myServiceName myServiceHost.exe - Verify service hosting

svcutil /t:xmlserializer myContractLibrary.exe - Generate serialization types for XmlSerializer types used by any Service Contracts in the assembly

Oriana answered 31/8, 2016 at 21:48 Comment(0)
S
4

For anyone still looking for the answer and could not get the 2012 version working, Visual Studio 2015 and .Net 4.5 have updated the svcutil.exe tool to use /serviceContract switch to generate a class that can then be implemented as a .svc service. You may need to provide /syncOnly /wrapped /messageContract switches as well depending on the original XSD's

Sciatica answered 14/6, 2016 at 13:46 Comment(0)
C
3

Svcutil.exe generates the service client proxy based on the Web Service Description Language (WSDL) from the service.

Open the visual studio command prompt and run the command

svcutil http://localhost/MyService/Service.svc  /Language=c#  /t:Code  /out:C:\Service\ServiceProxy.cs /config:C:\Service\ServiceProxy.config

it generates two files in C:\Service folder, the proxy file and config file,

More details here.

Cataclysm answered 10/6, 2018 at 1:55 Comment(0)
C
1

I think the .NET 4.5 Contract First Tool, integrated into Visual Studio 2012 as a build task, will help you generate the service files you need.

Service contracts often need to be created from existing services. In .NET Framework 4.5, data contract classes can be created automatically from existing services using the contract-first tool. To use the contract-first tool, the XML schema definition file (XSD) must be downloaded locally; the tool cannot import remote data contracts via HTTP.

http://msdn.microsoft.com/en-us/library/hh674270(v=vs.110).aspx

Colophon answered 2/6, 2014 at 19:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.