Getting information accross XML-RPC
QXmlRpc_Client provides a client for XML-RPC based web services, as defined
in this specification. If
the server you need to talk to responds to XML-RPC, you'll save yourself
a bunch of time if you use this plugin.
To look into how the plugin works in detail, let's consider a sample web service
defined at http://phpxmlrpc.sourceforge.net/server.php?methodName=examples.getStateName.
This example is really simple: given a number from 1 to 51, the service returns the name
of the USA state that has that "id". If you enter a number outside of that range, the
service returns an error. Go ahead and experiment with it in the text box below.
Let's now look at how to use the client. It's really straightforward - first,
initialize a QXmlRpc_Client object. Then, create an array of parameters
that you want to pass to the web service. Each parameter has to be wrapped with a
QXmlRpc_Client::prepare() call to format the parameters appropriately.
$aParams = array( QXmlRpc_Client::prepare((int) $this->txtState->Text) );
Then, make the actual request - note that requests are synchronous (i.e. execution
will go to the next line of code after you get the actual response). That said, if
you are making the call in a QAjaxAction, the QForm will still be responsive
to the user.
list($success, $response) = $client->request(
'phpxmlrpc.sourceforge.net', // server name
'/server.php', // server endpoint
'examples.getStateName',// method name
$aParams // parameters that we prepared above
Result of making a request is a key-value pair. The first variable
is a boolean that indicates success or failure; the second one is
an array with the details.