Reputation: 7810
It's just come to my attention that I'm going to have to interact with a SOAP API in the near future. Up until now though, I've only ever used REST APIs and never a SOAP API.
I've been reading about SOAP APIs and thus far my (very likely wrong) understanding is as follows:
I have two questions:
(If the sample SOAP API linked above is not a very good one, then I'm open to learning how to use SOAP with any other sample SOAP APIs that are available.)
Edit: pawelwaw, I wrote the following sample code to test everything out, but it seems like no matter what value I use for CityName
in the GetWeather
operation, I get no data back. Is my understanding incorrect, or is the SOAP API just not very good?
<?php
$client = new SoapClient('http://www.webservicex.com/globalweather.asmx?wsdl');
echo '<h2>Types:</h2>';
echo '<pre>';
var_dump($client->__getTypes());
echo '</pre>';
echo '<h2>Functions:</h2>';
echo '<pre>';
var_dump($client->__getFunctions());
echo '</pre>';
echo '<h2>GetCitiesByCountry:</h2>';
echo '<pre>';
echo htmlentities($client->GetCitiesByCountry([
'CountryName' => 'Poland'
])->GetCitiesByCountryResult);
echo '</pre>';
echo '<h2>GetWeather:</h2>';
echo '<pre>';
var_dump($client->GetWeather([
'CityName' => 'Krakow',
'CountryName' => 'Poland'
]));
echo '</pre>';
Upvotes: 0
Views: 1033
Reputation: 52
I ussally use SOAP api. And for this service You can use this sample code to get Cities of Country
<?php
$api = new SoapClient ( 'http://www.webservicex.com/globalweather.asmx?WSDL' );
$res = $api->GetCitiesByCountry(array( 'CountryName' =>"Poland"));
var_dump($res);
?>
then you are able to run 2nd method of this api to get Weather http://www.webservicex.com/globalweather.asmx?op=GetWeather
I hope, it helps.
It seems that function GetWeather ( http://www.webservicex.com/globalweather.asmx?op=GetWeather ) don't work correctly. when I filled values manually on site then there is no response with data, but for function GetCitiesByCountry ( http://www.webservicex.com/globalweather.asmx?op=GetCitiesByCountry ) returns data. I hadn't many expirience with API, but this should work, in my opinion there is a problem with this function in SOAP, because don't work via http also. I tested it via REST, and this function don't work according to specification.
Upvotes: 1