Possible to autogenerate to code using WSDL in Visual Studio

c#, visual-studio-2010, web-services

Solution

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!

Problem

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 Visual Studio 2010? I use C# normally. I just wondering is it possible to feed in the wsdl, and let visual studio auto generate some code to call the service? Thanks. And by the way, what does it mean "The test form is only available for requests from the local machine." in the url?

Original source