Create web service proxy in Visual Studio from a WSDL file

215,028

Solution 1

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 2

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 3

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

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

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.

Share:
215,028

Related videos on Youtube

Anne
Author by

Anne

Updated on July 08, 2022

Comments

  • Anne
    Anne almost 2 years

    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?

  • Shadow The Kid Wizard
    Shadow The Kid Wizard about 11 years
    This was already suggested in this existing answer why repeat?
  • Shadow The Kid Wizard
    Shadow The Kid Wizard about 11 years
    Faced same scenario and your suggestion saved me lots of frustration and probably some hair. Well deserved rep has been given to you. (As indirect result, you got +100 on all sites :))
  • guiomie
    guiomie about 9 years
    I tried this, the file imports, but I cant see in my code the classes
  • Hermann
    Hermann over 8 years
    I tried this method using MSVC 2015 but it refused to process wsdl file using URL. So I used the method described by Andrew M.
  • gkonuralp
    gkonuralp over 7 years
    Thanks! And you can use /o parameter for path of exported file. e.g. >wsdl.exe example.com/service.wsdl /o:C:\Users\X\Desktop
  • gkonuralp
    gkonuralp over 7 years
    I tried this from a development pc that doesn't have permission to access web service. Despite the .wsdl file is in local, it tried to connect service when I hit "Go". So I was not able to add reference. In this situation I think the solution of Andrew M. should be preferred. It worked good.
  • Blue Clouds
    Blue Clouds about 6 years
    and optionally add a namespace manually, covering all classes, to prevent conflict with similar files generated.
  • Blue Clouds
    Blue Clouds about 6 years
    Why asmx file when the question is about wsdl?
  • prakash r
    prakash r almost 5 years
    @jeffaudio im facing a similar problem I'm able to add service reference for web project but using wsdl.exe im not able to generate proxy file. any suggestion ..???
  • Daniel Krzyczkowski
    Daniel Krzyczkowski over 4 years
    This did not work for me unfortunately. I was able to generate files with wsdl.exe mentioned above.
  • Kevin Radcliffe
    Kevin Radcliffe about 4 years
    This is the only one that worked for me as the file in question needed to be downloaded after authentication first. Thanks!
  • Rohim Chou
    Rohim Chou about 3 years
    The proxy client code weren't generated by using "Add Service Reference" in my case. Have to additionally uncheck "Reuse types in all referenced assemblies" within Advanced configuration to get it to work. Another Post