PHP – SOAP sample
PHP simple SOAP sample
SOAP server file (soapserver.php):
<?php
// Set a function in SOAP server file
function hello($someone)
{
return "Hello " . $someone . "!";
}
// Create a new SOAP server
$server = new SoapServer(null, array('uri' => "urn://g31.local/ex/res"));
// Add function to SOAP server
$server->addFunction("hello");
// Handle SOAP server
$server->handle();
?>
SOAP client file (soapclient.php):
<?php
// Set new soap client
$client = new SoapClient(null, array(
'location' => "http://localhost/soapsample/soapserver.php",
'uri' => "urn://localhost/soapsample/req",
'trace' => 1 ));
// Call SOAP
$return = $client->__soapCall("hello", array("User"));
// Dispay request/response informations
echo("\nReturning value of __soapCall() call: " . $return);
echo("\nDumping request headers:\n" . $client->__getLastRequestHeaders());
echo("\nDumping request:\n" . $client->__getLastRequest());
echo("\nDumping response headers:\n" . $client->__getLastResponseHeaders());
echo("\nDumping response:\n" . $client->__getLastResponse());
?>