2 <head><title>xmlrpc - Webservice wrappper demo</title></head>
4 <h1>Webservice wrappper demo</h1>
6 <h2>Wrap methods exposed by server into php functions</h2>
8 <h3>The code demonstrates usage of some the most automagic client usage possible:<br/>
9 1) client that returns php values instead of xmlrpc value objects<br/>
10 2) wrapping of remote methods into php functions<br/>
11 See also proxy.php for an alternative take
15 include_once __DIR__ . "/../../src/Autoloader.php";
16 PhpXmlRpc\Autoloader::register();
18 $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
19 $client->return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
20 $resp = $client->send(new PhpXmlRpc\Request('system.listMethods'));
21 if ($resp->faultCode()) {
22 echo "<p>Server methods list could not be retrieved: error {$resp->faultCode()} '" . htmlspecialchars($resp->faultString()) . "'</p>\n";
24 echo "<p>Server methods list retrieved, now wrapping it up...</p>\n<ul>\n";
28 $wrapper = new PhpXmlRpc\Wrapper();
29 foreach ($resp->value() as $methodName) {
30 // $resp->value is an array of strings
31 if ($methodName == 'examples.getStateName') {
32 $callable = $wrapper->wrap_xmlrpc_method($client, $methodName);
34 echo "<li>Remote server method " . htmlspecialchars($methodName) . " wrapped into php function</li>\n";
36 echo "<li>Remote server method " . htmlspecialchars($methodName) . " could not be wrapped!</li>\n";
45 echo "Now testing function for remote method to convert U.S. state number into state name";
46 $stateNum = rand(1, 51);
47 // the 2nd parameter gets added to the closure - it is teh debug level to be used for the client
48 $stateName = $callable($stateNum, 2);