<?php
// Insert the NuSOAP code
require_once('/www/php/nusoap.php');
// This is location of the remote service
$client = new soapclient('http://localhost/helloworld-server.php');
// Check for any errors from the remote service
$err = $client->getError();
if ($err) {
echo '<p><b>Error: ' . $err . '</b></p>';
}
// Call the SOAP method on the remote service
$person = array('firstname' => 'Fred', 'age' => 22);
$result = $client->call(
'hello', // method name
array('message' => new soapval('id','Person',$person,false,'urn:AnyURN'))
);
// Check for any faults reported by the remote service
if ($client->fault) {
echo '<p><b>Fault: ';
print_r($result);
echo '</b></p>';
} else {
// Check for any errors from the remote service
$err = $client->getError();
if ($err) {
echo '<p><b>Error: ' . $err . '</b></p>';
} else {
// If everything is OK display the result
print $result['output_string'] . ' ';
if ( $result['allow'] == 1 ) {
print "You may continue...";
} else {
print "You are too young!";
}
}
}
?>
Remote Service (helloworld-server.php)
<?php
// Insert the NuSOAP code
require_once('/www/php/nusoap.php');
// Create an instance of the server
$server = new soap_server;
// This states the method which can be accessed.
$server->register(
'hello'
);
// This is the method
function hello($input) {
$output_string = 'Hello ' . $input['firstname'] .
'. You are ' . $input['age'] . ' years old.';
if ( $input['age'] >= 18 ) { $allow = 1; }
$output = array(
'output_string' => $output_string,
'allow' => $allow
);
return new soapval('return', 'HelloInfo', $output, false, 'urn:AnyURN');
}
// This returns the result
$server->service($HTTP_RAW_POST_DATA);
?>