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 the service call.

    In this example, the number of specified atoms (for example, C or O) in a SMILES string is calculated. 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 figure below shows the window setting.

    XML-RPC service settings

    Two running examples of calculating the number of C and O atoms in a SMILES string:

    Example calculations

    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");