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 xmlrpcval objects
2) wrapping of remote methods into php functions
return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
$r =& $c->send(new xmlrpcmsg('system.listMethods'));
if($r->faultCode())
{
echo "Server methods list could not be retrieved: error '".htmlspecialchars($r->faultString())."'
\n";
}
else
{
$testcase = '';
echo "Server methods list retrieved, now wrapping it up...
\n\n";
foreach($r->value() as $methodname) // $r->value is an array of strings
{
// do not wrap remote server system methods
if (strpos($methodname, 'system.') !== 0)
{
$funcname = wrap_xmlrpc_method($c, $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);
}
}
?>