简体   繁体   中英

Possible to autogenerate to code using WSDL in Visual Studio

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?

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:

输入服务的URL

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM