Submit a multicall request.

Submit a multicall request: query the XML-RPC endpoint for the methods xmlrpc_example.add and xmlrpc_example.subtract and report the result as a Drupal message. Drupal's XML-RPC client builds the system.multicall request automatically when there is more than one method to call.

Parameters

array $form: Form array.

array $form_state: Form_state array.

See also

xmlrpc()

xmlrpc_errno()

xmlrpc_error_msg()

xmlrpc_example_client_multicall_submit()

Related topics

1 string reference to 'xmlrpc_example_client_multicall_submit'
xmlrpc_example_client_form in xmlrpc_example/xmlrpc_example.module
Returns a form array to take input for two arguments.

File

xmlrpc_example/xmlrpc_example.module, line 548
Module file for xmlrpc_example module.

Code

function xmlrpc_example_client_multicall_submit($form, &$form_state) {
  $server = url($GLOBALS['base_url'] . '/xmlrpc.php', array(
    'external' => TRUE,
  ));

  /*
   * Drupal's built-in xmlrpc server supports the system.multicall method.
   *
   * To make a multicall request, the main invoked method should be the
   * function 'system.multicall', and the arguments to make this call must be
   * defined as an array of single method calls, being the array keys the
   * service methods to be called, and the array elements the method arguments.
   *
   * See the code below this comment as example.
   */

  // Build an array of several calls, Drupal's xmlrpc built-in support will
  // construct the correct system.multicall request for the server.
  $options = array(
    'xmlrpc_example.add' => array(
      (int) $form_state['values']['num1'],
      (int) $form_state['values']['num2'],
    ),
    'xmlrpc_example.subtract' => array(
      (int) $form_state['values']['num1'],
      (int) $form_state['values']['num2'],
    ),
  );

  // Make the xmlrpc request and process the results.
  $result = xmlrpc($server, $options);
  if ($result === FALSE) {
    drupal_set_message(t('Error return from xmlrpc(): Error: @errno, Message: @message', array(
      '@errno' => xmlrpc_errno(),
      '@message' => xmlrpc_error_msg(),
    )));
  }
  else {
    drupal_set_message(t('The XML-RPC server returned this response: <pre>@response</pre>', array(
      '@response' => print_r($result, TRUE),
    )));
  }
}