SOAP to JSON using PHP

For anyone that wants to translate output from a SOAP webservice using WLSD to JSON… Here is an example script that shows you the basicsšŸ™‚

This is a working example.

You need at least PHP 5.1 for this example to work!

<?php
// Setup and connect the soap client object
try{
	$sc = @new SoapClient('http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL');
} catch (Exception $e) {
	echo $e->getMessage();
}

// Fetch the uri parameter //
if(isset($_GET{'c'}) && !empty($_GET{'c'})){
	$country{'name'} = addslashes(ucwords($_GET{'c'}));
}else{
	$country{'name'} = 'FALSE';
}

// Query the soap webservice
$result = $sc->CountryISOCode(array('sCountryName' => $country{'name'}));
$result = $sc->FullCountryInfo( array(sCountryISOCode => $result->CountryISOCodeResult));

// Output the Json code
echo json_encode($result->FullCountryInfoResult);


print('<h2>Functions described in wsdl</h2><br\>');
foreach($sc->__getFunctions() as $key => $value){
	echo "$key => $value <br/>";
}

print('<h2>Types described in wsdl</h2><br\>');
foreach($sc->__getTypes() as $key => $value){
	echo "$key => $value <br/>";
}

?>

Goodluck , and happy scripting!šŸ™‚

About Chris Gralike

Momenteel ben ik manager van de afdeling business continuity bij de zakelijke IT dienstverlener AMIS Services BV. Sinds 2003 ben ik actief in de ICT branche. Tussen 2003 en nu heb ik verschillende rollen vervuld. In de rollen: systeem- en netwerkbeheer, system engineer, servicemanager en nu practice manager ben ik in contact gekomen met uiteenlopende technologieƫn, methodologieƫn, ideeƫn, oplossingen en innovaties. Een rijke ervaring waarmee ik de klanten van Conclusion en AMIS elke dag probeer te ondersteunen. Mijn credo: 'Altijd opzoek een win-win tussen business en technologie.'

Posted on July 21, 2011, in PHP and tagged , , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: