PHPBuilder - The web of services: using XML_RPC Page 10



RSS Twitter
Articles Php Functions

The web of services: using XML_RPC - Page 10

by: Luis Argerich
|
March 29, 2001

Writing Servers.

Building a sever is really easy with the classes provided by useful inc, you have to create a server by instantiating a constructor this way:

<?php

$s
=new xmlrpc_server( array("examples.myFunc" =>
                array(
"function" => "foo")));
?>
What you pass to the constructor is an asociative array of asociative arrays. The array have as keys the name of the methods to implement, each method has as key an array indicating with key "function" the name of a function to call for the method. In the example the procedure "examples.myFunc" calls function "foo", foo will be called a method handler for this reason.
Writing method handlers.
A method handler is easy this is a skeleton:

<?php

function foo ($params
{
    global 
$xmlrpcerruser// import user errcode value

    // $params is an Array of xmlrpcval objects
    
    
if ($err
    {
          
// this is an error condition
          
return new xmlrpcresp(0$xmlrpcerruser+1// user error 1
          
"There's a problem, Captain");
    } 
    else {
          
// this is a successful value being returned
          
return new xmlrpcresp(new xmlrpcval("All's fine!""string"));
    }
}

?>
As you can see you just check for errors and return an error (starting from $xmlrpcerruser+1) or a xmlrpcresp if everything went ok, all the rest of the wor is done by the class.

« 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.