更新时间:2023-02-16 13:35:16
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:
Put in the URL for the asmx (without the method in the querystring), give the reference a name and click OK:
That will generate the proxy code you need for making the call:
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!