XML-RPC

XML-RPC Service uses the standard XML-RPC protocol to access remote calculations. The XML for the request is automatically generated from the provided attributes and arguments, and the response is parsed to unwrap the result of service call.

This manual will give you a walk-through on how to use XML-RPC services.

Examples

Example #1

In this example we want to calculate the number of specified atoms (e.g. C or O) in a SMILES string. The example service will call the following PHP code:

<?php
class TestService {
public function countAtoms($smiles, $atom) {
$count = 0;
$lastIndex = strpos($smiles, $atom);
while($lastIndex !== false) {
$count++;
if($lastIndex + 2 < strlen($smiles)) {
$next = substr($smiles, $lastIndex + 1, 1);
if(ctype_alpha($next) && $next === strtolower($next)) {
$count--; //not counting
}
}
$lastIndex = strpos($smiles, $atom, $lastIndex + 1);
}
return $count;
}
}
?>

The actual window of setting looks like this:

images/download/attachments/41125593/image2015-12-4_14_5_36.png

Fig. 1 Settings of the Preferences window to set up the service

We put here 2 running examples of calculating the number of C and O atoms in a SMILES string.

images/download/attachments/41125593/image2015-12-4_14_7_49.png

Fig. 2 Examples of calculating specified atoms in SMILES strings

Calling XML-RPC Services from API

Here is an API example of calling XML-RPC services:

 XMLRPCServiceDescriptor descriptor = new XMLRPCServiceDescriptor();
descriptor.setURL("http://sample.server.net/xmlrpc");
descriptor.setMethodName("SampleService.countAtoms");
descriptor.addArgument(ServiceArgument.createArgument(""));
descriptor.addArgument(ServiceArgument.createArgument(""));
 
Object result = null;
try {
result = descriptor.getServiceHandler().callService(descriptor, "C1CCNCCC1", "C");
} catch (ServiceException e) {
System.err.println("Service call failed.");
}
System.out.println("Synchronized call returned: " + String.valueOf(result));
 
descriptor.getServiceHandler().callService(descriptor, new AsyncCallback<Integer>() {
 
@Override
public void onSuccess(Integer result) {
System.out.println("Asynchronous call returned: " + result);
}
 
@Override
public void onFailure(ServiceException caught) {
System.err.println("Asynchronous call failed.");
}
}, "C1CCNCCC1", "C");