Webservice wrappper demo
Wrap methods exposed by server into php functions
The code demonstrates usage of the most automagic client usage possible:
1) client that returns php values instead of xmlrpc value objects
2) wrapping of remote methods into php functions
return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
$resp = $client->send(new PhpXmlRpc\Request('system.listMethods'));
if ($resp->faultCode()) {
echo "Server methods list could not be retrieved: error {$resp->faultCode()} '" . htmlspecialchars($resp->faultString()) . "'
\n";
} else {
$testCase = '';
$wrapper = new PhpXmlRpc\Wrapper();
echo "Server methods list retrieved, now wrapping it up...
\n\n";
foreach ($resp->value() as $methodName) {
// $r->value is an array of strings
// do not wrap remote server system methods
if (strpos($methodName, 'system.') !== 0) {
$funcName = $wrapper->wrap_xmlrpc_method($client, $methodName);
if ($funcName) {
echo "- Remote server method " . htmlspecialchars($methodName) . " wrapped into php function " . $funcName . "
\n";
} else {
echo "- Remote server method " . htmlspecialchars($methodName) . " could not be wrapped!
\n";
}
if ($methodName == 'examples.getStateName') {
$testCase = $funcName;
}
}
}
echo "
\n";
if ($testCase) {
echo "Now testing function $testCase: remote method to convert U.S. state number into state name";
$stateNum = 25;
$stateName = $testCase($stateNum, 2);
echo "State number $stateNum is " . htmlspecialchars($stateName);
}
}
?>