XMLRPC server gives xml reponse in following way.
<methodResponse>
<fault>
<value>
<struct>
<member>
<name></name>
<value><int></int></value>
</member>
<member>
<name></name>
<value><string></string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>
But If you want to use your own xml format for response, then edit includes/xmlrpcs.inc
Comment following code at line number 77
$xml = xmlrpc_value_get_xml($r);
and while returning the value, return response in xml format. For example
function myservices_test($name){
$response = "<root>
<name>".$name."</name>
</root>";
return $response;
}
Showing posts with label webservices. Show all posts
Showing posts with label webservices. Show all posts
Tuesday, January 27, 2009
Request webservices in drupal 6
1. Following is the xml format for sending the request
$xmlrequest= "<?xml version='1.0'?>
<methodCall>
<methodName>myservices.test</methodName>
<params>
<param>
<value>
<string></string>
<int></int>
</value>
</param>
</params>
</methodCall>";
$ch = curl_init('http://localhost/drupal/services/xmlrpc');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $xmlrequest);
$result = curl_exec ($ch);
echo $result;
curl_close ($ch);
Save the file and execute in the web browser.
Note:
2. methodname will be the name of method in your service.
3. If you want to pass parameters then send it in following format
Creating your own Webservices with drupal 6
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.
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:
Posts (Atom)