Service module example: Echo service

Last modified: December 1, 2009 - 02:23

This service can be useful as an example, and as a test to make sure the services are functioning. This module simply replies with the message it is sent.

<?php
/**
* Implementation of hook_help().
*/
function echo_service_help($section) {
  switch (
$section) {
    case
'admin/help#services_node':
      return
t('<p>Provides echo methods to services applications. Requires services.module.</p>');
    case
'admin/modules#description':
      return
t('Provides echo methods to services applications. Requires services.module.');
  }
}

/**
* Implementation of hook_service()
*/
function echo_service_service() {
  return array(
   
// echo.echo
   
array(
     
'#method'   => 'echo.echo',
     
'#callback' => 'echo_service_echo',
     
//'#auth'     => false,
     
'#return'   => 'struct',
     
'#args'     => array(
        array(
         
'#name'         => 'message',
         
'#type'         => 'string',
         
'#description'  => t('The message to return.'),
        )),
     
'#help'     => t('Returns an object containing a sessid and user.'))
     
  );
}

function
echo_service_echo($message) {
 
 
$return = new stdClass();
 
$return->sessid = session_id();
 
$return->message = $message;
 
  return
$return;
}
?>

To install, in your modules directory make a directory named echo_service and install the above file as echo_service.module. Then put the following in that directory as echo_service.info. Then go to Administer > Site building > Modules and enable the Echo Service that shows up.

; $Id$
name = Echo Service
description = Provides echo services, such as if you want a ping ability to make sure the service is alive.
package = Services - services
dependencies = services
project = "services"

For Drupal 6.X

;$Id$
name = "Echo Service"
description = "Provides echo services, such as if you want a ping ability to make sure the service is alive."
core = 6.x
dependencies[] = services

Can anyone write example

kilemol - February 4, 2009 - 08:49

Can anyone write example client-script for this service, please?

Look at SOAP::Lite for Perl

porkchop_d_clown - April 17, 2009 - 18:38

it's easy to use and has some good tutorials.

client-script

isagarjadhav - April 30, 2009 - 19:55

i also need example of this client-script

S

yep, still no eye dear

matslats - October 22, 2009 - 13:52

I've spent half a day on this subject and I still don't know how to send requests, except that it must be by POST

Sample Client Script

bstewart - December 3, 2009 - 03:27

Here is a sample client script. It is a standalone PHP script that uses the Pearl XML_RPC2 library (Seems to be most straightforward to use).

http://drupal-dev.blogspot.com/2009/12/drupal-services-module.html

Ben Stewart
www.eintel.com.au

 
 

Drupal is a registered trademark of Dries Buytaert.