Thufir
Thufir

Reputation: 8497

how to call GetWeather method on webservicex web service?

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

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

Specifically, this method:

GetWeather Method string GetWeather(string CityName, string CountryName)

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?

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>

The script I have:

(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")

Upvotes: 0

Views: 2069

Answers (1)

vrdse
vrdse

Reputation: 3154

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.

Instead of $webservicex.GetWeather("Netherlands","Woensdrecht") this would be $webservicex.GetWeather("Woensdrecht","Netherlands").

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

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. ;)

Upvotes: 2

Related Questions