In this silly (really) example we build a server that given a number "n" returns "n*2", and a client that
uses the method to determine "5*2" WOW!
The server:
<?php
include("xmlrpc.inc");
include("xmlrpcs.inc");
function foo ($params)
{
global $xmlrpcerruser; // import user errcode value
// $params is an Array of xmlrpcval objects
$vala=$params->params[0];
$sval=$vala->scalarval();
$ret=$sval*2;
return new xmlrpcresp(new xmlrpcval($ret, "int"));
}
if ($HTTP_POST_VARS["number"]!="")
{
$f=new xmlrpcmsg('product',
array(new xmlrpcval($HTTP_POST_VARS["number"], "int")));
$c=new xmlrpc_client("/xmlrpc/servfoo.php", "luigi.melpomenia.com.ar", 80);
$c->setDebug(0);
$r=$c->send($f);
$v=$r->value();
if (!$r->faultCode())
{
print "Number ". $HTTP_POST_VARS["number"] . " is " .
$v->scalarval() . "<BR>";
print "<HR>I got this value back<BR><PRE>" .
htmlentities($r->serialize()). "</PRE><HR>\n";
}
else
{
print "Fault: ";
print "Code: " . $r->faultCode() .
" Reason '" .$r->faultString()."'<BR>";
}
}
print "<FORM METHOD=\"POST\">
<INPUT NAME=\"number\" VALUE=\"${number}\"><input type=\"submit\" value=\"go\" name=\"submit\"></FORM><P>
enter a number";
?>
Conclusions.
There's lot of infraestructure work to make the web of services XML_RPC enabled, there must be a catalog
or indexing mechanism for distributed procedures and better interfaces to handle XML_RPC from programming
languages, perhaps a XML_RPC PHP extension will do the work.
There will be lot of news about XML_RPC and the web of services in the future, we'd better watch.