如何在asp.net mvc中使用www.webservicex.net/uszip.asmx

时间:2022-12-04 08:11:40

I'm trying to consume this webservice...

我正在尝试使用这个网络服务......

http://www.webservicex.net/uszip.asmx

http://www.webservicex.net/uszip.asmx

When I add a web reference to this web service the methods it provides do not match what the asmx say.

当我向此Web服务添加Web引用时,它提供的方法与asmx所说的不匹配。

I get methods like this....

我得到这样的方法....

ZipcodeLookup.GetInfoByZIPCompletedEventArgs
ZipcodeLookup.GetInfoByZIPCompletedEventHandler

And I have no idea how to use these. Am I doing something wrong when adding the reference or could someone possibly shed some light on to how I use these methods?

我不知道如何使用这些。添加引用时我做错了什么,或者有人可能会对我如何使用这些方法有所了解?

Thanks!

谢谢!

1 个解决方案

#1


1  

Adding a Web Reference is an older deprecated approach to WebServices (although it still works great). For a service like this you need to add a Service Reference. To do this, right click on refrences in your project and choose Add Service Reference. Enter the URL in the address textbox and click "Go". You then see a list of services available at the address you entered. Choose "USZip" in this case and enter a namespace (ZipcodeLookup).

添加Web引用是一种较旧的Web服务旧方法(虽然它仍然很有用)。对于此类服务,您需要添加服务参考。为此,请右键单击项目中的引用,然后选择“添加服务引用”。在地址文本框中输入URL,然后单击“开始”。然后,您会在输入的地址中看到可用的服务列表。在这种情况下选择“USZip”并输入命名空间(ZipcodeLookup)。

Your usage would now be

你的用法现在是

        var service = new ZipcodeLookup.USZipSoapClient();
        XmlNode result1 = service.GetInfoByAreaCode("410");
        XmlNode result2 = service.GetInfoByCity("Annapolis");
        XmlNode result3 = service.GetInfoByState("MD");
        XmlNode result4 = service.GetInfoByZIP("21401");

As @mattytommo says, you will get methods and the classes associated with the web service, meaning that if a web service returns a type of person you will get a DTO type class called Person.

正如@mattytommo所说,您将获得与Web服务关联的方法和类,这意味着如果Web服务返回一种类型的人,您将获得名为Person的DTO类型类。

Hope this helps.

希望这可以帮助。

#1


1  

Adding a Web Reference is an older deprecated approach to WebServices (although it still works great). For a service like this you need to add a Service Reference. To do this, right click on refrences in your project and choose Add Service Reference. Enter the URL in the address textbox and click "Go". You then see a list of services available at the address you entered. Choose "USZip" in this case and enter a namespace (ZipcodeLookup).

添加Web引用是一种较旧的Web服务旧方法(虽然它仍然很有用)。对于此类服务,您需要添加服务参考。为此,请右键单击项目中的引用,然后选择“添加服务引用”。在地址文本框中输入URL,然后单击“开始”。然后,您会在输入的地址中看到可用的服务列表。在这种情况下选择“USZip”并输入命名空间(ZipcodeLookup)。

Your usage would now be

你的用法现在是

        var service = new ZipcodeLookup.USZipSoapClient();
        XmlNode result1 = service.GetInfoByAreaCode("410");
        XmlNode result2 = service.GetInfoByCity("Annapolis");
        XmlNode result3 = service.GetInfoByState("MD");
        XmlNode result4 = service.GetInfoByZIP("21401");

As @mattytommo says, you will get methods and the classes associated with the web service, meaning that if a web service returns a type of person you will get a DTO type class called Person.

正如@mattytommo所说,您将获得与Web服务关联的方法和类,这意味着如果Web服务返回一种类型的人,您将获得名为Person的DTO类型类。

Hope this helps.

希望这可以帮助。