Possible to autogenerate to code using WSDL in Visual Studio

前端 未结 2 413
遥遥无期
遥遥无期 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!

    0 讨论(0)
  • 2020-12-31 23:19

    Visual studio can generate code for wsdl/webservice referenced by an URL even it outside on your local machine. However, the test form accessed by browser just can be access on local machine (localhost).

    But you still can test the webservice over internet by other tool like soapUI. This tool useful for me to test webservice over internet.

    0 讨论(0)
提交回复
热议问题