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!

// Setup and connect the soap client object
	$sc = @new SoapClient('');
} catch (Exception $e) {
	echo $e->getMessage();

// Fetch the uri parameter //
if(isset($_GET['c']) && !empty($_GET['c'])){
	$country['name'] = addslashes(ucwords($_GET['c']));
	$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);

<h2>Functions described in wsdl</h2>
foreach($sc->__getFunctions() as $key => $value){
	echo "$key => $value

<h2>Types described in wsdl</h2>
foreach($sc->__getTypes() as $key => $value){
	echo "$key => $value


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. 2 Comments.

  1. Although this article helped me greatly I have never seen this before $country{‘name’} = ‘FALSE’;

    where can i read about using {} instead of [] for array keys?

  2. You cant, it was a typo that I didn’t pay much attention to.
    (was prob. tired, sorry for that).

    Even though it works (php weakly typed), you should use the [”] notation where possible being best practice and all.

    Corrected the code accordingly šŸ™‚

Leave a Reply

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

You are commenting using your 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: