Saturday, January 24, 2009

Calling Web Services using PHP5

Problem: how to call .NET Web services operation with multiple parameters using PHP5.

Below is the sample code to call .NET Web service using PHP5

Note that you need to enable soap client first by uncommenting or adding the below line in file php.ini

// file GlobalWeather.php


// specify WSDL Web service that we want to call
$wsdl = '';

// create SoapClient object
$client = new SoapClient($wsdl);

// in case if we call from KKU network which needs to go through KKU proxy
//,array('proxy_host' => "",'proxy_port' => 8088));

// initialize method name
$methodName = 'GetWeather';

// initialize method parameters
$params = array('CityName'=>'Khon Kaen','CountryName'=>'Thailand');

// initialize soapAction
$soapAction = 'http://www.webserviceX.NET/GetWeather';

// calling WS operation using soapCall
$objectResult = $client->__soapCall($methodName, array('parameters'=> $params), array('soapaction' => $soapAction));

// save the response
$response = $objectResult->GetWeatherResult;

// display response
echo $response;


This is the result from using file GlobalWeather.php

No comments: