How to reference a WSDL file using Visual Studio Code?

Manual Creation (from scratch)

If building from scratch and don't care about how Visual Studio does it, you can start with some basics from this solution here, as well as the other links referenced in the accepted solution on the same page.

Manual Creation using the same method Visual Studio uses

For reference, some of the files generated by the Visual Studio add reference method below, are stored within a subfolder Web References/Example (where Example is the name of the variable used to access the reference) and contains the following :

.map file

<?xml version="1.0" encoding="utf-8"?>
<DiscoveryClientResultsFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Results>
    <DiscoveryClientResult referenceType="System.Web.Services.Discovery.ContractReference" url="http://example.com/api/index.php?wsdl" filename="index.wsdl" />
  </Results>
</DiscoveryClientResultsFile>

.wsdl file (same name as the 'filename' parameter from above)

This file is the complete raw wsdl source file (well formatted xml).

reference file

This file contains code to initialize all the methods and properties and is the base class which extends System.Web.Services.Protocols.SoapHttpClientProtocol

The properties assigned to the class (sorry I am stripping from an old VB.NET project: look like the following :

<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.6.1586.0"),  _
 System.Diagnostics.DebuggerStepThroughAttribute(),  _
 System.ComponentModel.DesignerCategoryAttribute("code"),  _
 System.Web.Services.WebServiceBindingAttribute(Name:="ExampleAPIBinding", [Namespace]:="urn:ExampleAPI"),  _
 System.Xml.Serialization.SoapIncludeAttribute(GetType(MyCustomType1)),  _
 System.Xml.Serialization.SoapIncludeAttribute(GetType(MyCustomType2)),  _

 Partial Public Class ExampleAPI
    Inherits System.Web.Services.Protocols.SoapHttpClientProtocol

 End Class

.datasource (1 file for each type)

Example code

<?xml version="1.0" encoding="utf-8"?>
<!--
    This file is automatically generated by Visual Studio .Net. It is
    used to store generic object data source configuration information.
    Renaming the file extension or editing the content of this file may
    cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="MyMethodName" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
   <TypeInfo>ExampleAPI.SOAP.ClientMerchant, Web References.SOAP.Reference.vb.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>

Use Visual Studio to build it for you, then open up again in VSCode

Inside Visual Studio, you can do the following (and copy the results out to your VSCode project)

Step 1

Right-click your project in Project explorer, and select Add > Service Reference..

Add > Service Reference


Step 2

Click [Advanced] on this screen

Add Service Reference


Step 3

Click [Add Web Reference] on this screen

Service Reference Settings


Step 4

Enter your full URL to the WSDL location and press Enter.

Add Web Reference


Finally

If successful (well formatted WSDL is found), the [Add Reference] button will be enabled. Click that, and it will add the reference to your project.


You can also use donet-svcutil

https://learn.microsoft.com/en-us/dotnet/core/additional-tools/dotnet-svcutil-guide?tabs=dotnetsvcutil2x

Example

dotnet-svcutil https://svn.apache.org/repos/asf/airavata/sandbox/xbaya-web/test/Calculator.wsdl