4.11. XmlRpcClient Class

Note: This class is not available with the PO_NO_NETWORK parse option.

The XmlRpcClient class provides easy access to XML-RPC web services. This class inherits all public methods of the HTTPClient class. The inherited HTTPClient methods are not listed in this section, see the section on the HTTPClient class for more information on methods provided by the parent class. For low-level XML-RPC functions, see the XML-RPC functions in XML Functions.

The XmlRpcClient class understands the following protocols in addition to the protocols supported by the HTTPClient class:

Table 4.467. XmlRpcClient Class Protocols

Protocol

Default Port

SSL?

Description

xmlrpc

80

No

Unencrypted XML-RPC protocol over HTTP

xmlrpcs

443

Yes

XML-RPC protocol over HTTP with SSL/TLS encryption


The XmlRpcClient supplies default values for HTTP headers as follows:

Table 4.468. XmlRpcClient Default, but Overridable Headers

Header

Default Value

Accept

text/xml

Content-Type

text/xml

User-Agent

Qore XML-RPC Client v0.8.0

Connection

Keep-Alive


Table 4.469. XmlRpcClient Class Method Overview

Method

Except?

Description

XmlRpcClient::constructor(softbool $no_connect = False)

XmlRpcClient::constructor(hash $opts, softbool $no_connect = False)

Y

Creates the XmlRpcClient object based on the parameters passed.

XmlRpcClient::destructor

N

Destroys the XmlRpcClient object and closes any open connections.

XmlRpcClient::copy()

Y

Copying objects of this class is not supported, an exception will be thrown.

XmlRpcClient::call(string $method, ...) returns hash

Y

Calls a remote method using a variable number of arguments for the method arguments and returns the response as qore data structure.

XmlRpcClient::callArgs(string $method, any $args) returns hash

Y

Calls a remote method using a single value after the method name for the method arguments and returns the response as qore data structure.

XmlRpcClient::callWithInfo(reference $info, string $method, ...) returns hash

Y

Same as the XmlRpcClient::call() except the first argument must be an lvalue reference, which is used as an output variable, where information about the HTTP request and response is written.

XmlRpcClient::callArgsWithInfo(reference $info, string $method, hash $args) returns any

Y

Same as the XmlRpcClient::callArgs() except the first argument must be an lvalue reference, which is used as an output variable, where information about the HTTP request and response is written.

XmlRpcClient::setEventQueue() returns nothing

XmlRpcClient::setEventQueue(Queue $queue) returns nothing

N

Sets a Queue object to receive HTTPClient and Socket events or clears the queue if no argument is passed.


4.11.1. XmlRpcClient::constructor()

Synopsis

Creates the XmlRpcClient object based on the parameters passed and by default immediately attempts to establish a connection to the server (pass a boolean True value as the second argument to establish a connection on demand). See HTTPClient::constructor() and HTTPClient::connect() for information on possible exceptions.

Prototype

XmlRpcClient::constructor(softbool $no_connect = False)

XmlRpcClient::constructor(hash $opts, softbool $no_connect = False)

Example
my XmlRpcClient $xrc(("url":"http://hostname/RPC2"));

Table 4.470. Arguments for XmlRpcClient::constructor()

Argument

Description

hash $opts

an option hash, see HTTPClient::constructor() Option Hash Keys for valid keys in this hash.

softbool $no_connect = False

If this optional argument is passed with a value of True, then the object will not attempt to make a connection immediately to the remote socket, but instead will wait until a connection is required and made implicitly or manually established with the parent class' HTTPClient::connect() method.


4.11.2. XmlRpcClient::destructor()

Synopsis

Destroys the XmlRpcClient object and closes any open connections.

Example
delete $xrc;

4.11.3. XmlRpcClient::copy()

Synopsis

Copying objects of this class is not supported, an exception will be thrown.

Table 4.471. Exceptions thrown by XmlRpcClient::copy()

err

desc

XMLRPCCLIENT-COPY-ERROR

objects of this class may not be copied


4.11.4. XmlRpcClient::call()

Synopsis

Calls a remote method using a variable number of arguments for the method arguments and returns the response as qore data structure. See HTTPClient::send(), makeXMLRPCCallString(), and parseXMLRPCResponse() for information on possible exceptions.

Prototype

XmlRpcClient::call(string $method, ...) returns hash

Example
$result = $xrc.call("method.name", $arg1, $arg2);

Table 4.472. Arguments for XmlRpcClient::call()

Argument

Description

string $method

The XML-RPC method name to call

...

Optional arguments for the method.


Table 4.473. Return Values for XmlRpcClient::call()

Return Type

Description

hash

If the call was successful, the response information will be found in the key 'params'. If an error occurred then the error information can be found under the 'fault' key.


4.11.5. XmlRpcClient::callArgs()

Synopsis

Calls a remote method using a single value after the method name for the method arguments and returns the response as qore data structure. See HTTPClient::send(), makeXMLRPCCallString(), and parseXMLRPCResponse() for information on possible exceptions.

Prototype

XmlRpcClient::callArgs(string $method, any $args) returns hash

Example
$result = $xrc.callArgs("method.name", $arg_list);

Table 4.474. Arguments for XmlRpcClient::callArgs()

Argument

Description

string $method

The XML-RPC method name to call

any $args

An optional list of arguments (or single argument) for the method.


Table 4.475. Return Values for XmlRpcClient::callArgs()

Return Type

Description

hash

If the call was successful, the response information will be found in the key 'params'. If an error occurred then the error information can be found under the 'fault' key.


4.11.6. XmlRpcClient::callWithInfo()

Synopsis

Like the XmlRpcClient::call() method, except requires an lvalue reference as the first argument that will be used as an output variable providing information about the HTTP request and response made to effect the XML-RPC call.

Prototype

XmlRpcClient::callWithInfo(reference $info, string $method, ...) returns hash

Example
$result = $xrc.callWithInfo(\$info, "method.name", $arg1, $arg2);

Table 4.476. Arguments for XmlRpcClient::callWithInfo()

Argument

Description

reference $info

A reference to an lvalue that will be used as an output variable providing information about the HTTP request and response made to effect the XML-RPC call.

string $method

The XML-RPC method name to call

...

Optional arguments for the method.


Table 4.477. Return Values for XmlRpcClient::callWithInfo()

Return Type

Description

hash

If the call was successful, the response information will be found in the key 'params'. If an error occurred then the error information can be found under the 'fault' key.


4.11.7. XmlRpcClient::callArgsWithInfo()

Synopsis

Like the XmlRpcClient::callArgs() method, except requires an lvalue reference as the first argument that will be used as an output variable providing information about the HTTP request and response made to effect the XML-RPC call.

Prototype

XmlRpcClient::callArgsWithInfo(reference $info, string $method, any $args) returns hash

Example
$result = $xrc.callArgsWithInfo(\$info, "method.name", $arg_list);

Table 4.478. Arguments for XmlRpcClient::callArgsWithInfo()

Argument

Description

reference $info

A reference to an lvalue that will be used as an output variable providing information about the HTTP request and response made to effect the XML-RPC call.

string $method

The XML-RPC method name to call

any $args

An optional list of arguments (or single argument) for the method.


Table 4.479. Return Values for XmlRpcClient::callArgswithInfo()

Return Type

Description

hash

If the call was successful, the response information will be found in the key 'params'. If an error occurred then the error information can be found under the 'fault' key.


4.11.8. XmlRpcClient::setEventQueue()

Synopsis

Sets a Queue object to receive HTTPClient and Socket events. To remove the event queue and stop monitoring events, pass NOTHING to the method. See Event Handling for more information.

Prototype

XmlRpcClient::setEventQueue() returns nothing

XmlRpcClient::setEventQueue(Queue $queue) returns nothing

Example
$xrc.setEventQueue($queue);

Table 4.480. Arguments for XmlRpcClient::setEventQueue()

Argument

Description

[Queue $queue]

To set the event queue, pass a Queue object; to clear the event queue, pass no argument to the function.