简体   繁体   English

可以在Visual Studio中使用WSDL自动生成代码

[英]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 您好,我希望使用测试以下功能: http//msrmaps.com/terraservice2.asmx?op = ConvertLonLatPtToNearestPlace

Is there some faster way I can test it out using Visual Studio 2010? 有没有更快的方法可以使用Visual Studio 2010测试它? I use C# normally. 我正常使用C#。 I just wondering is it possible to feed in the wsdl, and let visual studio auto generate some code to call the service? 我只是想知道是否可以输入wsdl,并让visual studio自动生成一些代码来调用服务? 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. 第一个也是最简单的方法(在我看来)是创建一个对该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: 输入asmx的URL(不包含查询字符串中的方法),为引用指定名称,然后单击“确定”:

输入服务的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: 从那里,您可以使用该代理代码来调用Web服务:

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. 第二种方法是使用visual studio附带的命令行WSDL.exe工具。 Launch a visual studio command prompt and type wsdl /? 启动visual studio命令提示符并键入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: 在我的例子中,我只是从http://msrmaps.com/terraservice2.asmx?wsdl下载了一份WSDL,将其保存到我的桌面并运行命令:

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

Generates the proxy class next to my WSDL file. 生成我的WSDL文件旁边的代理类。

One last thing... become best friends with soapUI as @Habibillah suggested. 最后一件事......正如@Habibillah建议的那样成为soapUI最好的朋友。 It's a fantastic tool for calling web services without having to write any code. 它是调用Web服务的绝佳工具,无需编写任何代码。

Hope that helps! 希望有所帮助!

Visual studio can generate code for wsdl/webservice referenced by an URL even it outside on your local machine. Visual Studio可以为URL引用的wsdl / webservice生成代码,即使它在本地计算机外部也是如此。 However, the test form accessed by browser just can be access on local machine (localhost). 但是,浏览器访问的测试表单只能在本地计算机上访问(localhost)。

But you still can test the webservice over internet by other tool like soapUI . 但您仍然可以通过其他工具(如soapUI)在Internet上测试Web服务。 This tool useful for me to test webservice over internet. 这个工具对我来说可以通过互联网测试web服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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