See README file of the Web service client module.

This is a sample way to call a WSClient operation:

  $service = wsclient_service_load('your ws service');
  
  $account = new stdClass;
  $account->name ='your user';
  $account->pass_raw ='your pass';
  
  // For own HTTPS certificates.
  $curl_options[CURLOPT_SSL_VERIFYPEER] = FALSE;
  // For own HTTP authorization.
  $curl_options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
  $curl_options[CURLOPT_USERPWD] = $account->name . ':' . $account->pass_raw;
  $service->settings['curl options'] = $curl_options;
  
  try {
    $result = $service->your_method();
  }
  catch (WSClientException $e) {
    watchdog('wsclient', $e->__toString());
    return null;
  }

  return $result;

This next example assumes that you have a POST method configured in a REST service. Use a parameter on the method as a placeholder to store your data.

Passing arguments to your methods is also a fairly straightforward process, in the following example a POST request is being made with a REST WSClient. Some data is being passed as the payload:

// Function that takes a $node to make a POST call with.
function example_post_call($node) {
  $service = wsclient_service_load('service_name');
  // An array that will be serialized into JSON or XML depending on your configuration.
  // Various settings in you service's "request formatter" determine how this array is
  // transmitted. Ensure that there is a parameter set in your method where this can be
  // stored.
  $data = array(
    'name' => $node->title,
  );

  try {
    // The method called here is the machine name of your operation.
    // You can also call invoke('my_post_method', $data) instead.
    // We pass $data in here, where it will be used as $arguments for this WSClient, 
    // which in turn will be used to create the 'parameters' and 'data' for the request.
    // If you have more parameters required for your service, those need to be passed
    // here too.
    $response = $service->my_post_method($data);
  }
  catch (WSClientException $exception) {
    watchdog('example', $exception->__toString(), array(), WATCHDOG_ERROR);
    return FALSE;
  }

  return $response;
}

/**
 * Implements hook_wsclient_rest_request_alter().
 */
function example_wsclient_rest_request_alter($request, $service) {
  // This hook can be used to modify anything in the $request object just before it is 
  // handed off to CURL. In this example, we want to unset the data from the
  // parameters, and an api key from the data. This is because the REST client takes all
  // the arguments and parameters and copies them into the data element.
  unset($request->parameters['RequestRootName']);
  unset($request->data['key']);
}

It should be noted, again, that anything passed to your REST service method ($data in the above example) is inserted into both the parameters and data of the request.

Comments

emptyvoid’s picture

Sadly the read me provides little documentation on how to create an entity object and send the value to the webservice method.

Perhaps entity_create() ?

Don't know.

Robert Foley Jr
Application Architect / Business Analyst / Information Designer
http://www.robertfoleyjr.com

chicodasilva’s picture

Can anyone provide an example with HTTP authentication?

thomashuang025’s picture

is that your_method() means operation where I put in hook_default_wsclient_service()
likes this?
$service->operations['your_method'] = $operation;

thomashuang025’s picture

The answer is YES

dineshw’s picture

Can you provide example of using we client module for using REST Web Service (Create method) for creating node with keeping Authentication option on for Web service.

Cheers
Dinesh Waghmare (LAMP)
UK, Surrey | India, Mumbai
Web Development | Digital Media Marketing | Strategic Consulting
--
m: +91 9867888266
(Drupal / Wordpress / SugarCRM )

rajatgusain’s picture

The documentation is based on the REST ws but I am looking for the SOAP web services consumption by the code.
I am having authentication parameter but not clear how to pass them where to keep the WSDL file.
Please help.

kumkum29’s picture

Hello rajatgusain,

have you found a solution for the authentification for a SOAP web service?

Thanks.

sumachaa’s picture

We are not getting the alter hook_wsclient_rest_request_alter in 1.0 version
What version this works?