1. Download services module from http://drupal.org/project/Services
2. Unzip the service module directory and copy inside sites/all/modules directory
3. Now Enable the module, for that you need to open web browser => navigate to your drupal website => Goto Site building => Modules => List => Enable services and XMLRPC Server => save configuration
4. Goto Site Building => Services => Setings => Uncheck Use keys & Use sessid boxes => save configuration
All settings are done. Now time to write your own services.
1. Create a directory for your service inside sites/all/modules directory, say myservices.
2. Here you need to create 3 files:
i) myservices.inc
ii) myservices.module
iii) myservices.info
3. Open myservices.info and write following lines
; $Id: myservices.info,v 1.5 2009/01/20 18:20:21 sheetal Exp $
name = My services
description = Expose basic services.
package = Services - service
version = VERSION
dependencies[] = services
core = 6.x
; Information added by drupal.org packaging script on 2008-12-11
version = "6.8"
project = "drupal"
datestamp = "1229018427"
4. Now open myservices.module
You should know about drupal module development for writing the webservices.
For example, create a function myservices_service().
function myservices_service(){
return array(
array(
'#method' => 'myservices.test',
'#callback' => 'myservices_test',
'#file' => array('file' => 'inc', 'module' => 'myservices'),
'#args' => array(
array(
'#name' => 'your_name',
'#type' => 'string',
'#description' => t('A valid name.'),
)
)
};
5. Now open myservices.inc. This file will contain the actual code
function myservices_test($name){
$response = "Welcome " . $name;
//your code will come here
return $response;
}
6. Everything is completed. Test your webservice by going to Site Building => Services => Browse
Here you will see the list of services which you have created, i.e. myservices.test
You will also see the XMLRPC server.
7. Now click on the services, you will see the output.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment