#native_company# #native_desc#
#native_cta#

The web of services: using XML_RPC Page 8

By Luis Argerich
on March 29, 2001













Writing Clients.

Writing a XML_RPC client implies:
  • Cretaing a XML_RPC request message
  • Setting XML_RPC parameters
  • Creating a XML_RPC message
  • Sending the message
  • Getting the response
  • Interpreting the response
Take a look at this example:

<?php

$f=new xmlrpcmsg('examples.getStateName',

               array(new 
xmlrpcval(14"int")));

$c=new xmlrpc_client("/RPC2""betty.userland.com"80);

$r=$c->send($f);

$v=$r->value();

if (!
$r->faultCode()) {

    print 
"State number "$HTTP_POST_VARS["stateno"] . " 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>";

}

?>



In the example we create a XML_RPC message to call the “examples.getStateName” method and we pass
an integer parameter of type “int” with the number 14. Then we create the RPC client indicating the
URL to call (path,domain and port). Then we send the message, receive a response object and check
for errors. If no errors are found we display the result.
Functions to program RPC clients:
A client is created with:
$client=new xmlrpc_client($server_path, $server_hostname, $server_port);
And the method to send a message is:
$response=$client->send($xmlrpc_message);
It returns and instance of xmlrpcresp. The message that we pass is an instance of xmlrpcmsg which
is created in the following way:
$msg=new xmlrpcmsg($methodName, $parameterArray);
Method name is the name of the method (procedure) to call, parameter array is a simple php array of xmlrpcval
objects. For example:
$msg=new xmlrpcmsg("examples.getStateName",
		  array(new xmlrpcval(23, "int")));






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