504 Part III: Advanced Topics
The service handles our “helloworld” call and responds with our favorite welcoming
message via a SOAP response.
<?php
function helloworld()
{
return "Hello World to user from ". $_SERVER['REMOTE_ADDR'].
" at ". date("h:i:s A");
}
$server = new SoapServer(null, array('uri' => "urn:helloworld"));
$server->addFunction("helloworld");
$server->handle();
?>
Back on the browser, we then receive the packet and parse it putting the payload into
the page.
function handleResponse(response)
{
var result = response.responseXML.getElementsByTagName("return");
$id("responseOutput").innerHTML = result[0].firstChild.nodeValue;
}
The operation and network trace of this SOAP example is shown in Figure 10-6, and the
example can be found at http://ajaxref.com/ch10/soapclient.html.
FIGURE 10-6 SOAPy Ajax request