PHP

You are here home > know-how > php > SOAP > Get Weather information with SOAP and WSDL

6.2 Get Weather information with SOAP and WSDL

Date: 09.09.2006

6.1 Autogenerate PHP Code from WSDL [  up  ] - [ top ] - [ A - Z ] 6.3 SOAP Error Handling

Client


<?php

	require_once 'SOAP/Client.php';
	require_once 'soap-weather-class.php';

	$weather = new StationInfo();

	$CityName = 'Zurich';
	$CountryName = 'Switzerland';

	echo $weather->GetWeather($CityName, $CountryName);


?>

The related Class file


<?php

class StationInfo extends SOAP_Client
{
    function StationInfo($path = 'http://www.webservicex.net/globalweather.asmx')
    {
	$this->SOAP_Client($path, 0);
    }

    function &GetWeather($CityName, $CountryName)
    {
	$GetWeather =& new SOAP_Value('{http://www.webserviceX.NET}GetWeather', false, $v = array('CityName' => $CityName, 'CountryName' => $CountryName));
	$result = $this->call('GetWeather',
			      $v = array('GetWeather' => $GetWeather),
			      array('namespace' => 'http://www.webserviceX.NET',
				    'soapaction' => 'http://www.webserviceX.NET/GetWeather',
				    'style' => 'document',
				    'use' => 'literal'));
	return $result;
    }

    function &GetCitiesByCountry($CountryName)
    {
	$GetCitiesByCountry =& new SOAP_Value('{http://www.webserviceX.NET}GetCitiesByCountry', false, $v = array('CountryName' => $CountryName));
	$result = $this->call('GetCitiesByCountry',
			      $v = array('GetCitiesByCountry' => $GetCitiesByCountry),
			      array('namespace' => 'http://www.webserviceX.NET',
				    'soapaction' => 'http://www.webserviceX.NET/GetCitiesByCountry',
				    'style' => 'document',
				    'use' => 'literal'));
	return $result;
    }
}

?>


XML Output


<?xml version="1.0" encoding="utf-16"?>
<CurrentWeather>
  <Location>Zurich-Kloten, Switzerland (LSZH) 47-29N 008-32E 432M</Location>
  <Time>Mar 16, 2006 - 07:20 AM EST / 2006.03.16 1220 UTC</Time>
  <Wind> from the ENE (060 degrees) at 10 MPH (9 KT):0</Wind>
  <Visibility> 3 mile(s):0</Visibility>
  <SkyConditions> mostly cloudy</SkyConditions>
  <Temperature> 35 F (2 C)</Temperature>
  <Wind>Windchill: 26 F (-3 C):1</Wind>
  <DewPoint> 26 F (-3 C)</DewPoint>
  <RelativeHumidity> 69%</RelativeHumidity>
  <Pressure> 30.06 in. Hg (1018 hPa)</Pressure>
  <Status>Success</Status>
</CurrentWeather>


Google
infoCopter   Web  

copyright by reto - created with mytexi