4

The Short, Short Version

Can wsdl.exe generate the exact same files that Visual Studio does when adding a Web Reference?

Alternatively:

What are the Windows CMD commands that will mimic what Visual Studio does when adding a Web Reference?

A Little More Detail

I have a VS2015 project that uses a Web Reference: https://webservices.netsuite.com/wsdl/v2016_2_0/netsuite.wsdl (NetSuite - bleh).

I can add the Web Service reference in Visual Studio (Project -> Add Service Reference -> Advanced -> Add Web Reference -> Enter URL -> Add Reference) and it will generate a whole bunch of .xsd and .datasource files:

Generated by Visual Studio

Everything is useable and happy. Yay.


However, when I use WSDL.exe, it only generates a single file: NetSuiteService.cs:

C:\CSharpPlayground\CSharpPlayground>mkdir "Web References\com.netsuite.webservices"

C:\CSharpPlayground\CSharpPlayground>wsdl.exe /:"Web References\com.netsuite.webservices" "https://webservices.netsuite.com/wsdl/v2016_2_0/netsuite.wsdl"
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 4.6.1055.0]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'C:\CSharpPlayground\CSharpPlayground\NetSuiteService.cs'.

I've poured over wdsl.exe /? and haven't found anything that looks like it would help me.

Is wsdl.exe not the right tool for the job?

Background

I am trying to get CI builds working for my project (we self-host a GitLab instance, so I'm using gitlab-ci). The project builds just fine on my development computer because these .xsd and .datasource files all exist.

However, they don't exist on the build machine. I found that I can update the WSDL data using a MSBuild target/task thanks to this answer. So I added that to my .csproj file and it successfully downloads the data from NetSuite - only to a single .cs file rather than the collection. Thus, the build fails.

I could simply check in all of the web reference files to git, but I'd rather not do that unless I absolutely have to.

Update 1 (2017-03-13 15:56 PDT)

@RasmusW below mentioned the newer scvutil.exe utility. This gets part of the way there - it generates the individual .xsd files (the .datasource files might not be needed).

However, the generated .xsd files are not named correctly. They are using the namespace value rather than the schemaLocation value.

For example, in the .wsdl file provided by NetSuite we have:

<xsd:import namespace="urn:types.accounting_2015_2.lists.webservices.netsuite.com" schemaLocation="https://webservices.netsuite.com/xsd/lists/v2015_2_0/accountingTypes.xsd"/>

The generated file is types.accounting_2015_2.lists.webservices.netsuite.com.xsd rather than accountingTypes.xsd.

In addition, there are other files generated by VS2015:

  • NetSuiteService.cs

    • This I can get by using wsdl.exe /out:"Web References\com.netsuite.webservices\\" https://webservices.netsuite.com/wsdl/v2015_2_0/netsuite.wsdl. It returns the exact same file as what VS2015 creates.
  • Reference.cs

    • No idea what this really is or how it's generated. It appears to be very similar to what's in NetSuiteService.cs though.
  • Reference.map

    • This is an xml file that has a bunch of DiscoveryClientResult items that map a url to a filename. I assume that this is how Visual Studio gets the names for the .xsd files, but I'm not sure.
    • Looks something like: <DiscoveryClientResult referenceType="System.Web.Services.Discovery.SchemaReference" url="https://webservices.netsuite.com/xsd/lists/v2015_2_0/accountingTypes.xsd" filename="accountingTypes.xsd" />
Community
  • 1
  • 1
dthor
  • 1,749
  • 1
  • 18
  • 45
  • 1
    Any particular reason that you want to use wsdl.exe and not svcutil.exe? For the difference between wsdl.exe and svcutil.exe, you can check out this question: http://stackoverflow.com/questions/18311816/wcf-proxy-generation-svcutil-exe-vs-wsdl-exe – RasmusW Mar 13 '17 at 21:21
  • @RasmusW Because I wasn't aware of `svcutil.exe` :-) A very cursory check of that tool results in the same thing - a single file being generated. I'm currently looking over the options to see if there are flags I can set. – dthor Mar 13 '17 at 21:48

1 Answers1

1

Note: All of the below is specific to the WSDL file that I'm using (NetSuite), so it may not work for you. But hey, it's worth trying!

After some experimentation, this is what I've come up with to answer the question:

What are the Windows CMD commands that will mimic what Visual Studio does when adding a Web Reference?

  1. VS makes the Web References folder and namespace folder. This needs to be done because the following steps do not necessarily create the folders for you. Note that you'll need to change your folder names accordingly. In this example, com.netsuite.webservices is the namespace that everything gets put in.

    SET OUR_DIR="%PROJECT_NAME%\Web References\com.netsuite.webservices"
    mkdir "%OUR_DIR%"
    
  2. Use the WSDL.exe tool to create the main .cs file.

    wsdl.exe /out:"%OUR_DIR%\NetSuiteService.cs" %WSDL_URL%
    

    Note that we're using wsdl.exe, even though it's deprecated in favor of svcutil.exe. This is because the two tools output different files when generating source code from the wsdl file. I don't know why this is - it may be specific to the wsdl file I'm using or it may be for another reason.

  3. Create the .xsd files with the disco.exe tool. Hehe fun name.

    disco.exe /out:"%OUR_DIR%" %WSDL_URL%
    

    This generates the individual .xsd files that were shown in the screenshot in the question above. It also creates the map file that maps names to make things pretty (see Update 1 in question). However, I haven't been able to figure out how to change the output name of the mapfile (default is results.discomap), so I just do it manually:

    move "%OUR_DIR%\results.discomap" "%OUR_DIR%\Reference.map"
    

The above steps give you almost everything - the files match exactly what Visual Studio (2015) creates, but Reference.cs is still missing. This file appears to be very similar to the WSDL-generated code NetSuiteService.cs but puts everything in the namespace from step 1 (the folder, com.netsuite.webservices).

Sadly I haven't been able to figure out how to generate this Reference.cs file.

My only solution was to generate this file on my dev machine, copy it to somewhere I can easily access, and then download/copy it to the build folder during CI builds. For example, I put it in the C:\Utilities folder on the build machine, so I can pull it in with

copy "C:\Utilities\NetSuite_DO_NOT_DELETE__Reference.cs" "%OUR_DIR%\Reference.cs"
dthor
  • 1,749
  • 1
  • 18
  • 45