51

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.

1
  • I actually also tried wsdl.exe /server or /serverinterface it is still generating the .cs class.
    – alice7
    Sep 8, 2009 at 17:50

6 Answers 6

83

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()
     {
         //you'll have to write your own business logic 
         return "Hello SOAP World";
     }
 }
2
  • 3
    Also you can put /out:"path\to\folder" to put the generated code in a certain location.
    – Joshua G
    Sep 26, 2013 at 18:59
  • 3
    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) Jun 26, 2018 at 10:11
4

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" %>
1
  • 1
    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.
    – alice7
    Sep 8, 2009 at 17:49
4

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

add -> web service

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()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/addition", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    string addition(int firtNo, int secNo);
}

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
3

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).

1

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.

1
  • 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. Jul 9, 2013 at 20:26
1

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.

1
  • this is the easiest and straight approach from vs cmd window. Feb 5, 2018 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.