PHPBuilder - The web of services: using XML_RPC Page 9



RSS Twitter
Articles Php Functions

The web of services: using XML_RPC - Page 9

by: Luis Argerich
|
March 29, 2001

An xmlrpcval object may be created using this forms:

<?php

$myVal
=new xmlrpcval($stringVal);
$myVal=new xmlrpcval($scalarVal"int" "boolean" "string" "double" "dateTime.iso8601" "base64");
$myVal=new xmlrpcval($arrayVal"array" "struct");

?>
The first creates a xmlrpc string value, the second creates a scalar value indicating value and type, the third one may be used to create complex objects by grouping other xmlrpc vals in structures such as arrays or structures as following:

<?php

$myArray
=new xmlrpcval(array(
              new 
xmlrpcval("Tom"), new xmlrpcval("Dick"),
              new 
xmlrpcval("Harry")), "array");

          
$myStruct=new xmlrpcval(array(
              
"name" => new xmlrpcval("Tom"),
              
"age" => new xmlrpcval(34"int"),
              
"geek" => new xmlrpcval(1"boolean")), "struct");
?>
The response object is of type xmlrpcresp and is obtained calling the method "send" from a client object, in a server you can create an xmlrpc resp using:
$resp=new xmlrpcresp($xmlrpcval);
In the client you use the method:
$xmlrpcVal=$resp->value();
To get the xmlrpcval from the response. Then you can use this method to get a PHP variable representing the response:
$scalarVal=$val->scalarval();
There're two useful functions to deal with complex types:
These functions reside in xmlrpc.inc.
$arr=xmlrpc_decode($xmlrpc_val);
Returns a PHP array stuffed with the values found in the xmlrpcval $xmlrpc_val, translated into native PHP types.
$xmlrpc_val=xmlrpc_encode($phpval);
Returns an xmlrpcval populated with the PHP values in $phpval. Works recursively on arrays and structs. Note that there's no support for non-base types like base-64 values or date-times.
Writing clients is a easy task in PHP, you can build web-based clients for XML_RPC services using PHP.

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
10
|
11
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Luis Argerich

Comment:



Comment:

(Maximum characters: 1200). You have characters left.