Create web service proxy in Visual Studio from a WSDL file

前端 未结 7 1894
别跟我提以往
别跟我提以往 2020-11-29 17:24

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 Vis

相关标签:
7条回答
  • 2020-11-29 17:44

    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.

    0 讨论(0)
  • 2020-11-29 17:45

    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.

    0 讨论(0)
  • 2020-11-29 17:47

    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.

    0 讨论(0)
  • 2020-11-29 17:53

    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.

    0 讨论(0)
  • 2020-11-29 17:54

    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
    
    0 讨论(0)
  • 2020-11-29 17:56

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

    file://your_path/your_file.wsdl
    
    0 讨论(0)
提交回复
热议问题