Hello.

I install the Drupal and Web Service model (Web Service).
The web service download from address:

http://drupal.org/project/webservices

But I don't know how to use it. Anyone can tell me How can I call Drupal web service from other Application?
How to type the URL for call Drupal web service?

Thanks.

Northman

Comments

dporto99@gmail.com’s picture

OK, here is a very simple example. I am trying to do more complex things, but I am still working on it.

require_once("..xmlrpc/lib/xmlrpc.inc");
function rpcexample_retrieve_node($nid) {
  // Load the XML-RPC for PHP library from wherever you've put it
  // File path relative to the Drupal root
  

  // Turn the node ID into a standard XMLRPC data type, for transmission
  $nid = new xmlrpcval($nid, "int");

  // Create an XMLRPC message
  $m = new xmlrpcmsg('node.view',
    // Note that the "optional" second parameter is required, but it can be empty.
    // If you omit it, services returns wrong-parameter-number errors
    array($nid, new xmlrpcval(array(), "array"))
  );
	  
  // Create a connection to the remote server
  // Note the root URL is services/xmlrpc. If you don't turn the
  // separate XMLRPC server module on, this will result in HTTP 404
  $c = new xmlrpc_client('/services/xmlrpc', 'drupal6.localhost', 80);

  // Send the message to the remote server and get the response
  $r = $c->send($m);
  
  // The return value is a collection of xmlrpcval objects
  // which you can loop over to turn back into PHP data types
  return $r->value();
}

if (isset($_POST['node_id']) && $_POST['node_id']!=''){
	$array = rpcexample_retrieve_node(addslashes($_POST['node_id']));
	echo '<p>'.$array->serialize().'</p>';
	echo '<p>'.$array->kindOf().'</p>';
	echo '<p>'.$array->structmem('body')->serialize().'</p>';
}

Remember that you need to use the service module on your Drupal site.