#### [SOLVED] how to generate web service out of wsdl

By alice7

Client provided me the wsdl to generate the web service.But when I used the wsdl.exe command it generated the .cs class out of it. I consumed that class in my web service and when I provided the wsdl to client it didn't match their schema. Actually I want the .asmx to be automatically generated from the wsdl so that I could fill in the web method. So that it will exactly match their schema. Hope it make sense.

#### @abdul rehman kk 2019-08-02 10:51:17

step-1

open -> Visual Studio 2017 Developer Command Prompt


step-2

WSDL.exe  /OUT:myFile.cs WSDLURL  /Language:CS /serverInterface

• /serverInterface (this to create interface from wsdl file)
• WSDL.exe (this use to create class from wsdl. this comes with .net
• /OUT: (output file name)

step-2

create new "Web service Project"

step-3

step-4

copy all code from myFile.cs (generated above) except "using classes" eg:

 /// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.1055.0")]
[System.Web.Services.WebServiceBindingAttribute(Name="calculoterServiceSoap",Namespace="http://tempuri.org/")]

public interface ICalculoterServiceSoap {

/// <remarks/>
[System.Web.Services.WebMethodAttribute()]
}


step-4

past it into your webService.asmx.cs (inside of namespace) created above in step-2

step-5

inherit the interface class with your web service class eg:

public class WebService2 : ICalculoterServiceSoap


#### @Red Swan 2016-01-15 07:28:18

This may be very late in answering. But might be helpful to needy: How to convert WSDL to SVC :

1. Assuming you are having .wsdl file at location "E:\" for ease in access further.
2. Prepare the command for each .wsdl file as: E:\YourServiceFileName.wsdl
3. Permissions: Assuming you are having the Administrative rights to perform permissions. Open directory : C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
4. Right click to amd64 => Security => Edit => Add User => Everyone Or Current User => Allow all permissions => OK.
5. Prepare the Commands for each file in text editor as: wsdl.exe E:\YourServiceFileName.wsdl /l:CS /server.
6. Now open Visual studio command prompt from : C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts\VS2013 x64 Native Tools Command Prompt.
7. Execute above command.
8. Go to directory : C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64, Where respective .CS file should be generated.

9.Move generated CS file to appropriate location.

this is the easiest and straight approach from vs cmd window.

#### @Neilb 2010-05-20 15:50:58

You can generate the WS proxy classes using WSCF (Web Services Contract First) tool from thinktecture.com. So essentially, YOU CAN create webservices from wsdl's. Creating the asmx's, maybe not, but that's the easy bit isn't it? This tool integrates brilliantly into VS2005-8 (new version for 2010/WCF called WSCF-blue). I've used it loads and always found it to be really good.

#### @Dave Ziegler 2013-07-09 20:26:32

I was going to note this as well, although I never had much luck with it myself (WSCF Blue in particular). Maybe I used an early version or something.

#### @p.campbell 2009-09-10 17:04:31

There isn't a magic bullet solution for what you're looking for, unfortunately. Here's what you can do:

• create an Interface class using this command in the Visual Studio Command Prompt window:

wsdl.exe yourFile.wsdl /l:CS /serverInterface
Use VB or CS for your language of choice. This will create a new .cs or .vb file.

• Create a new .NET Web Service project. Import Existing File into your project - the file that was created in the step above.

• In your .asmx.cs file in Code-View, modify your class as such:

 public class MyWebService : System.Web.Services.WebService, IMyWsdlInterface
{
[WebMethod]
public string GetSomeString()
{
return "Hello SOAP World";
}
}


#### @Joshua G 2013-09-26 18:59:01

Also you can put /out:"path\to\folder" to put the generated code in a certain location.

#### @Jeremy Ray Brown 2014-10-03 23:00:43

Thank you, huge help

#### @Wouter Vanherck 2018-06-26 10:11:31

The command wsdl.exe C:Folder\File.wsdl /l:CS /ServerInterface /out:C:Folder did it for me. For all those that don't recognise wsdl.exe in the command prompt: You can use it in the Developer Command Prompt for VS 2017 (found under start when VS17 is installed)

#### @John Saunders 2009-09-10 16:54:16

You cannot guarantee that the automatically-generated WSDL will match the WSDL from which you create the service interface.

In your scenario, you should place the WSDL file on your web site somewhere, and have consumers use that URL. You should disable the Documentation protocol in the web.config so that "?wsdl" does not return a WSDL. See <protocols> Element.

Also, note the first paragraph of that article:

This topic is specific to a legacy technology. XML Web services and XML Web service clients should now be created using Windows Communication Foundation (WCF).

#### @marc_s 2009-09-08 17:03:09

How about using the wsdl /server or wsdl /serverinterface switches? As far as I understand the wsdl.exe command line properties, that's what you're looking for.

- ADVANCED -


/server

Server switch has been deprecated. Please use /serverInterface instead.
Generate an abstract class for an xml web service implementation using
ASP.NET based on the contracts. The default is to generate client proxy
classes.


On the other hand: why do you want to create obsolete technology solutions? Why not create this web service as a WCF service. That's the current and more modern, much more flexible way to do this!

Marc

UPDATE:

When I use wsdl /server on a WSDL file, I get this file created:

[WebService(Namespace="http://.......")]
public abstract partial class OneCrmServiceType : System.Web.Services.WebService
{
/// <remarks/>
[WebMethod]
public abstract void OrderCreated(......);
}


This is basically almost exactly the same code that gets generated when you add an ASMX file to your solution (in the code behind file - "yourservice.asmx.cs"). I don't think you can get any closer to creating an ASMX file from a WSDL file.

You can always add the "yourservice.asmx" manually - it doesn't really contain much:

<%@ WebService Language="C#" CodeBehind="YourService.asmx.cs"
Class="YourServiceNamespace.YourServiceClass" %>


#### @alice7 2009-09-08 17:49:24

NO that's not actually Im looking for.It would generate the proxy class which I don't want.I want to generate abc.asmx automatically.And I thought for WCF but went to be simple by making web service.

### [SOLVED] How do I generate a random int number?

• 2010-04-24 23:09:11
• Rella
• 2135353 View
• 1780 Score
• Tags:   c# random