XMLRPC multiple requests
greenSkin - May 6, 2008 - 23:57
| Project: | Services |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed |
Description
Multiple requests does not seem to work via XMLRPC.

#1
Please explain what you were doing/trying to achive?
#2
We are trying to make a single xmlrpc call that requests more than one method. For example, according to the Drupal api docs the first parameter is the URL, the second is the method being requested, and additional parameters will be passed to that method (for single request). For a multiple request, the docs say that the first parameter again is the URL but the second should be an array with call arrays and the first element in the call array should be the method name and further elements should be the methods needed parameters. Unless I understand it wrong and are trying to implement it wrong, the multiple request does not work. I do not know if it is an issue with XMLRPC or whether it is a problem with Services. I am leaning towards it's an issue with Services because of the nature of the return error, though I don't remember what it was off hand.
As we are still in development with what we are building, we have currently gotten by with just making separate XMLRPC calls, but would like to find a fix for this before too long.
#3
The services / xmlrpc server changes very little with how core's xmlrpc functions. All it really does is pass a keyed array, as you would with normal hook_xmlrpc, to core xmlrpc. That said, its likely that is is a core issue rather than a Services issue.
This is obviously very important, however, you and your team likely have way more experience with this than myself. If you find/found its a problem with Services, do let me know and I'll be happy to work with yout to get a patch in.
Thanks,
Scott
#4
Drupal's xmlrpc() function does indeed work with multi-calls as the example given in #3 at #255509: xmlrpc multiple requests.
The error returned when trying to use the Services xmlrpc server when calling 'system.multicall' is 'Method system.multicall does not exist'. My best guess is that Services is rejecting the method 'system.multicall' since it is not defined as a Services method.
#5
Strange ok, someone should have a look at this.
Services XMLRPC is actually served through Drupal's XMLRPC. The xmlrpc_server.module actually implements hook_xmlrpc and exposes the service methods through the hook to Drupal XMLRPC, so it should in theory be combining all services with methods implemented by hook_xmlrpc. It seems not to be the case, but just FYI.
#6
Can you provide some example calls that you are making? I have a couple of ideas where things might be going wrong.
#7
#8
Here's an example.
<?php
//XMLRPC multicall example
$url = 'http://example.com/services/xmlrpc';
$calls = array();
$calls[] = array('methodName' => 'system.connect',
'params' => array()
);
$calls[] = array('methodName' => 'node.get',
'params' => array(1, array())
);
$res = xmlrpc($url,'system.multicall', $calls);
echo '<pre>';
print_r($res);
echo '</pre>';
?>
#9
subscribing, I would love to see a working system.multicall too.
#10
Sample call:
<?php
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
include_once './includes/xmlrpc.inc';
include_once './includes/xmlrpcs.inc';
$url = 'http://example.org/services/xmlrpc';
$calls = array(
array('user.login', 'name', 'password'),
array('system.listMethods'),
array('user.logout'),
array('system.methodHelp', 'system.listMethods'),
);
$return = xmlrpc($url, $calls);
?>
Attached is a patch that apparently makes it working and possibly gives some hints on what is going wrong.
#11
That patch doesn't work for me. It looks like it starts to loop through all of the methods in the multicall, but then just returns the results from the first one?
#12
My guess is that instead of returning on the call we need to do the following:
<?phpif ($method_name == 'system.multicall') {
$responses = array();
$params = $xmlrpc_server->message->params;
foreach($params[0] as $key => $method) {
if ($i == $key) {
$i++;
if (!in_array($method['methodName'], $core_methods)) {
$responses[] = services_method_call($method['methodName'], $method['params']);
}
}
}
return $responses;
}
?>
Note I haven't tested the concept because I don't have time to set up the required test environment to prove my theory. Patch attached. The nice thing though is that this can be happily be applied to all versions of service without issue.
#13
I don't get why you need the $call_index, or why you need to exclude the four system functions. Can you elaborate on that? It seems like we should be able to just roll through the methods and return the merged array.
I like this functionality but I don't see it compelling enough to hold up releasing the 2.x branch over unless someone wants to drive it home and test it.
#14
I could be wrong but my understanding is that Services doesn't have the method 'system.multicall' registered. Would adding it to the list of available methods work?
#15
That is what the above patch does. Marking this postponed, but if someone gets a good patch in before a release is rolled I'll be happy to check it out.