如何在 webservicex 网络服务上调用 GetWeather 方法? [英] how to call GetWeather method on webservicex web service?

查看:46
本文介绍了如何在 webservicex 网络服务上调用 GetWeather 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读下面的输出时,对于获取天气的脚本MemberType 根据 WSDL?

When reading the output below, for a script to get the weather, the MemberType describes the API per the WSDL?

更广泛的问题是,从 powershell 中,我如何知道我可以调用哪些方法?而且,它们是如何调用的?

The broader question is, from powershell, how do I know which methods I can invoke? And, how are they invoked?

具体来说,这个方法:

GetWeather 方法 string GetWeather(string CityName, string CountryName)

然而,当我尝试调用该方法时,我得到:Data Not Found.为什么?调用该方法的正确方法是什么?我需要先调用另一个方法吗?

Yet when I try to invoke that method I get: Data Not Found. Why? What's the correct way to call that method? Do I need to call another method first?

Windows 上使用 .NET,希望了解天气:

Using .NET on Windows, looking to get the weather:

PS C:\Users\thufir>
PS C:\Users\thufir>
PS C:\Users\thufir> .\Desktop\ps\weather3.ps1


   TypeName: WebServiceProxy.GlobalWeather

Name                                 MemberType Definition
----                                 ---------- ----------
Disposed                             Event      System.EventHandler Disposed(System.Object, System.EventArgs)
GetCitiesByCountryCompleted          Event      WebServiceProxy.GetCitiesByCountryCompletedEventHandler GetCitiesByCountryCompleted(System.Object, WebServiceProxy.GetCitiesByCountryCompletedEventArgs)
GetWeatherCompleted                  Event      WebServiceProxy.GetWeatherCompletedEventHandler GetWeatherCompleted(System.Object, WebServiceProxy.GetWeatherCompletedEventArgs)
Abort                                Method     void Abort()
BeginGetCitiesByCountry              Method     System.IAsyncResult BeginGetCitiesByCountry(string CountryName, System.AsyncCallback callback, System.Object asyncState)
BeginGetWeather                      Method     System.IAsyncResult BeginGetWeather(string CityName, string CountryName, System.AsyncCallback callback, System.Object asyncState)
CancelAsync                          Method     void CancelAsync(System.Object userState)
CreateObjRef                         Method     System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)
Discover                             Method     void Discover()
Dispose                              Method     void Dispose(), void IDisposable.Dispose()
EndGetCitiesByCountry                Method     string EndGetCitiesByCountry(System.IAsyncResult asyncResult)
EndGetWeather                        Method     string EndGetWeather(System.IAsyncResult asyncResult)
Equals                               Method     bool Equals(System.Object obj)
GetCitiesByCountry                   Method     string GetCitiesByCountry(string CountryName)
GetCitiesByCountryAsync              Method     void GetCitiesByCountryAsync(string CountryName), void GetCitiesByCountryAsync(string CountryName, System.Object userState)
GetHashCode                          Method     int GetHashCode()
GetLifetimeService                   Method     System.Object GetLifetimeService()
GetType                              Method     type GetType()
GetWeather                           Method     string GetWeather(string CityName, string CountryName)
GetWeatherAsync                      Method     void GetWeatherAsync(string CityName, string CountryName), void GetWeatherAsync(string CityName, string CountryName, System.Object userState)
InitializeLifetimeService            Method     System.Object InitializeLifetimeService()
ToString                             Method     string ToString()
AllowAutoRedirect                    Property   bool AllowAutoRedirect {get;set;}
ClientCertificates                   Property   System.Security.Cryptography.X509Certificates.X509CertificateCollection ClientCertificates {get;}
ConnectionGroupName                  Property   string ConnectionGroupName {get;set;}
Container                            Property   System.ComponentModel.IContainer Container {get;}
CookieContainer                      Property   System.Net.CookieContainer CookieContainer {get;set;}
Credentials                          Property   System.Net.ICredentials Credentials {get;set;}
EnableDecompression                  Property   bool EnableDecompression {get;set;}
PreAuthenticate                      Property   bool PreAuthenticate {get;set;}
Proxy                                Property   System.Net.IWebProxy Proxy {get;set;}
RequestEncoding                      Property   System.Text.Encoding RequestEncoding {get;set;}
Site                                 Property   System.ComponentModel.ISite Site {get;set;}
SoapVersion                          Property   System.Web.Services.Protocols.SoapProtocolVersion SoapVersion {get;set;}
Timeout                              Property   int Timeout {get;set;}
UnsafeAuthenticatedConnectionSharing Property   bool UnsafeAuthenticatedConnectionSharing {get;set;}
Url                                  Property   string Url {get;set;}
UseDefaultCredentials                Property   bool UseDefaultCredentials {get;set;}
UserAgent                            Property   string UserAgent {get;set;}
<NewDataSet>
  <Table>
    <Country>Netherlands</Country>
    <City>Amsterdam Airport Schiphol</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Maastricht Airport Zuid Limburg</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>De Bilt</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Deelen</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Eindhoven</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Groningen Airport Eelde</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Gilze-Rijen</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>De Kooy</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Leeuwarden</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Rotterdam Airport Zestienhoven</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Soesterberg</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Twenthe</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Valkenburg</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Volkel</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Vlieland</City>
  </Table>
  <Table>
    <Country>Netherlands</Country>
    <City>Woensdrecht</City>
  </Table>
  <Table>
    <Country>Netherlands Antilles</Country>
    <City>Flamingo Airport, Bonaire</City>
  </Table>
  <Table>
    <Country>Netherlands Antilles</Country>
    <City>Hato Airport, Curacao</City>
  </Table>
  <Table>
    <Country>Netherlands Antilles</Country>
    <City>Roosevelt Airport Saint Eustatius</City>
  </Table>
  <Table>
    <Country>Netherlands Antilles</Country>
    <City>Juliana Airport, Saint Maarten</City>
  </Table>
</NewDataSet>
Data Not Found


PS C:\Users\thufir>

我拥有的脚本:

(New-Object System.Net.WebClient).Proxy.Credentials =  [System.Net.CredentialCache]::DefaultNetworkCredentials
$url = "http://www.webservicex.net/globalweather.asmx?wsdl"
$webservicex = New-WebServiceProxy -Uri $url -namespace WebServiceProxy -Class GlobalWeatherSoap
$webservicex | gm
$webservicex.GetCitiesByCountry("Netherlands")
$webservicex.GetWeather("Netherlands","Woensdrecht")

推荐答案

基本上你自己已经回答了这个问题.Get-Member 向您展示了如何调用该方法.GetWeather(string CityName, string CountryName).因此,您必须首先将 CityName 指定为字符串,然后将 CountryName 指定为字符串.

You basically answered the question already by yourself. Get-Member shows you how to invoke the method. GetWeather(string CityName, string CountryName). Thus you have to specify first the CityName as a string, and second the CountryName as a string.

代替 $webservicex.GetWeather("Netherlands","Woensdrecht") 这将是 $webservicex.GetWeather("Woensdrecht","Netherlands").

GetCitiesByCountry 输出显示国家和城市都有效.

The GetCitiesByCountry output shows, that both, the country and the city are valid.

输出 Data Not Found 是网络服务的响应,即该方法工作正常,但网络服务找不到该城市的天气.您可以使用 HTTP GET 请求.

The output Data Not Found is the response of the webservice, i.e. the method worked just fine, but the webservice could not find the weather for the this city. You can verify that your browser with a HTTP GET request.

不幸的是,网络服务似乎无法找到任何城市的天气.我的网络服务坏了.;)

Unfortunately it seems that the webservice can't find the weather for any city. Imo the webservice is broken. ;)

这篇关于如何在 webservicex 网络服务上调用 GetWeather 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆