It is possible to auto-generate code using WSDL in Visual Studio

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

Is there a faster way to test it with Visual Studio 2010? I usually use C #. I'm just wondering if it is possible to file in wsdl and let visual studio automatically generate code to call the service? Thanks.

And by the way, what does this mean: "The test form is available only for requests from the local machine." in the url?

+6
source share
2 answers

There are several things you can do to create this code. The first and easiest way (in my opinion) is to create a link to this URL. Here are some screenshots:

Right click on your project, add a link to the service:

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

Put the url for asmx (no method in querystring), give the link a name and click OK:

Enter the URL for the service

This will create the proxy code needed to make the call:

Notice the new service reference in the project

From there, you can simply use this 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 WSDL.exe command-line WSDL.exe that comes with visual studio. Run the visual studio command line and enter wsdl /? . This will show you the options for the application. In my case, I just took a copy of WSDL from http://msrmaps.com/terraservice2.asmx?wsdl , saved it on my desktop, and ran the command:

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

Creates a proxy class next to my WSDL file.

One last thing ... to become best friends with soapUI, as Habibilla suggested. This is a fantastic tool to call web services without having to write code.

Hope this helps!

+12
source

Visual studio can generate code for wsdl / webservice referenced by the url even on an external machine. However, the test form available by the browser can only be accessed on the local computer (localhost).

But you can still test the web service over the Internet with another tool like soapUI . This tool is useful for me to test a web service over the Internet.

+2
source

All Articles