Possible to autogenerate to code using WSDL in Visual Studio

前端 未结 2 417
遥遥无期
遥遥无期 2020-12-31 22:47

Hi I wish to use test the following function: http://msrmaps.com/terraservice2.asmx?op=ConvertLonLatPtToNearestPlace

Is there some faster way I can test it out using

2条回答
  •  难免孤独
    2020-12-31 23:08

    There are a few things that you can do to generate that code. The first and easiest way (in my opinion) is to create a service reference to that URL. Here are some screenshots:

    Right click on your project, add a service reference:

    Right click on the project and choose to add a service reference

    Put in the URL for the asmx (without the method in the querystring), give the reference a name and click OK:

    Enter the URL for the service

    That will generate the proxy code you need for making the call:

    Notice the new service reference in the project

    From there, you can just use that proxy code to call the web service:

    TerraService.TerraServiceSoapClient client = new TerraService
        .TerraServiceSoapClient("TerraServiceSoap");
    string place = client.ConvertLonLatPtToNearestPlace(
        new TerraService.LonLatPt { Lat = 47.6532, Lon = -122.135479 });
    

    The second method is to use the command-line WSDL.exe tool that comes with visual studio. Launch a visual studio command prompt and type wsdl /?. That will show you the parameters for the application. In my case, I just pulled down a copy of the WSDL from http://msrmaps.com/terraservice2.asmx?wsdl, saved it to my desktop and ran the command:

    wsdl /o:./terraservice.cs terraservice.wsdl
    

    Generates the proxy class next to my WSDL file.

    One last thing... become best friends with soapUI as @Habibillah suggested. It's a fantastic tool for calling web services without having to write any code.

    Hope that helps!

提交回复
热议问题