#native_company# #native_desc#
#native_cta#

The web of services: using XML_RPC Page 11

By Luis Argerich
on March 29, 2001



















A sample XML_RPC Client and Server.

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"));

}

$s=new xmlrpc_server( array("product" => array("function" => "foo")));

?>



The client:

<?php

include("xmlrpc.inc");

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.
–Luis

1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
|
11