Create web service proxy in Visual Studio from a WSDL file

C#.NetVisual StudioWeb ServicesWsdl

C# Problem Overview


My application needs to talk to a web service that hasn't got an online WSDL definition. The developers however supplied me with a WSDL file.

With a public WSDL Visual Studio can generate this code for me using the Service Reference wizard. But it doesn't seem to work without a public WSDL.

How do I generate the code for talking to this web service using this WSDL file?

C# Solutions


Solution 1 - C#

Using WSDL.exe didn't work for me (gave me an error about a missing type), but I was able to right-click on my project in VS and select "Add Service Reference." I entered the path to the wsdl file in the Address field and hit "Go." That seemed to be able to find all the proper types and added the classes directly to my project.

Solution 2 - C#

Try using WSDL.exe and then including the generated file (.cs) into your project.

Fire up the Visual Studio Command prompt (under visual studio/tools in the start menu) then type

>wsdl.exe [path To Your WSDL File]

That'll spit out a file, which you copy/move and include in your project. That file contains a class which is a proxy to your sevice, Fire up an instance of that class, and it'll have a URL property you can set on the fly, and a bunch of methods that you can call. It'll also generate classes for all/any complex objects passed across the service interface.

Solution 3 - C#

On the side note: if you have all of the files locally (not only wsdl file but also xsd files) you can invoke wsdl.exe in that manner:

wsdl.exe [path to your wsdl file] [paths to xsd files imported by wsdl]

That way wsdl.exe can resolve all dependecies locally and correctly generates proxy class.

Maybe it will save somebody some time - it solves "missing type" error when service is not avaliable online.

Solution 4 - C#

There's a Microsoft Doc for creating your WCF proxy from the command line .

You can find your local copy of wsdl.exe in a location similar to this: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools (Learn more here)

In the end your Command should look similar to this:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\wsdl.exe"
 /language:CS /n:"My.Namespace" https://www.example.com/service/wsdl

Solution 5 - C#

Try the WSDL To Proxy class tool shipped with the .NET Framework SDK. I've never used it before, but it certainly looks like what you need.

Solution 6 - C#

save the file on your disk and then use the following as URL:

file://your_path/your_file.wsdl

Solution 7 - C#

Since the true Binding URL for the web service is located in the file, you could do these simple steps from your local machine:

  1. Save the file to your local computer for example:

    C:\Documents and Settings[user]\Desktop\Webservice1.asmx

  2. In Visual Studio Right Click on your project > Choose Add Web Reference, A dialog will open.

  3. In the URL Box Copy the local file location above C:\Documents and Settings[user]\Desktop\Webservice1.asmx, Click Next

  4. Now you will see the functions appear, choose your name for the reference, Click add reference

  5. You are done! you can start using it as a namespace in your application don't worry that you used a local file, because anyway the true URL for the service is located in the file at the Binding section

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnneView Question on Stackoverflow
Solution 1 - C#jeffaudioView Answer on Stackoverflow
Solution 2 - C#Andrew MView Answer on Stackoverflow
Solution 3 - C#Jarek MazurView Answer on Stackoverflow
Solution 4 - C#Serj SaganView Answer on Stackoverflow
Solution 5 - C#Steve DannerView Answer on Stackoverflow
Solution 6 - C#Evan CamilleriView Answer on Stackoverflow
Solution 7 - C#Israel MarguliesView Answer on Stackoverflow