如何在webservicex Web服务上调用GetWeather方法?

问题描述 投票:0回答:1

在阅读下面的输出for a script to get the weather时,MemberType描述了每个APIWSDL

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

具体来说,这种方法:

GetWeather Method string GetWeather(string CityName, string CountryName)

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

.NET上使用Windows,希望得到天气:

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")
.net windows powershell soap wsdl
1个回答
2
投票

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

而不是$webservicex.GetWeather("Netherlands","Woensdrecht")这将是$webservicex.GetWeather("Woensdrecht","Netherlands")

GetCitiesByCountry输出表明,国家和城市都是有效的。

输出Data Not Found是网络服务的响应,即方法工作正常,但网络服务无法找到这个城市的天气。您可以使用HTTP GET request验证您的浏览器。

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

© www.soinside.com 2019 - 2024. All rights reserved.