Testing Services 3.x beta with xmlrpc

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by joshon on March 5, 2011 at 6:16am

I have setup an endpoint called api.
It uses an xmlrpc server.
I have enabled system.connect in the resources tab.
I send this request:

POST http://mydomain.local/api HTTP/1.1
Accept: text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, text/css, image/png, image/jpeg, image/gif;q=0.8, application/x-shockwave-flash, video/mp4;q=0.9, flv-application/octet-stream;q=0.8, video/x-flv;q=0.7, audio/mp4, application/futuresplash, /;q=0.5
x-flash-version: 10,2,152,26
Content-Type: application/x-www-form-urlencoded
Content-Length: 102
User-Agent: Shockwave Flash
Host: mydomain.local
Pragma: no-cache
Cookie: SESSdce96b2191ab3bf38d2c87cf563b1f7d=t2cn1v5pg1rd7d9ptlpr89kpk4

<methodCall>
<methodName>system.connect</methodName>
<ignoreWhite>true</ignoreWhite>
</methodCall>

And I get this response:

HTTP/1.1 200 OK
Date: 2011年3月05日 05:25:18 GMT
Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.1
Expires: 1978年11月19日 05:00:00 GMT
Last-Modified: 2011年3月05日 05:25:18 GMT
Cache-Control: store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Connection: close
Content-Length: 378
Content-Type: text/xml

<?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>-32601</int></value>
</member>
<member>
<name>faultString</name>
<value><string>Server error. Requested method system.connect not specified.</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>

How should I correctly address system.connect ?

Categories:

Comments

Is it 6.x or 7.x ?

Posted by ygerasimov on March 5, 2011 at 9:33am

Do you have problems with Drupal 6 or Drupal 7 ?

In 7.x version it should work, but I am not sure about 6.x as there is prefixing for xmlrpc. So please try system.xmlrpc_connect. But I think we will remove prefixing like it was done in 7.x version of Services.

It is 6.x

Posted by joshon on March 5, 2011 at 5:34pm

Sorry I didn't mention that it was 6.x!
I abandoned it for now and went back to version 2.44.
I noticed that in the resources UI - the connect method was buried in a box labeled actions.
I tried system.actions.connect (desperate!) which didn't work - but it did make me think it was a scope issue that I didn't understand.
I did succeed in calling other methods - so it was working in principle - I just couldn't get system.connect to work - which was the core of the matter unfortunately.

i gave up on 3.x in d6 too. i

Posted by primerg on May 24, 2011 at 7:04pm

i gave up on 3.x in d6 too. i noticed in the cache it's not giving me the right method name. been trying to make it work in 3.x for hours while in 2.x i got it enabled for a few minutes.

XMLRPC is very difficult and

Posted by kylebrowning on May 24, 2011 at 7:11pm

XMLRPC is very difficult and might be broken for awhile in 6.x, Why not use something much simpler like REST?

I use mimic library

Posted by dealancer on January 4, 2012 at 3:38pm

I use mimic library (http://mimic-xmlrpc.sourceforge.net/) for testing XMLRPC in services. Works pretty fine and easy for me. So what you need to do with it:

  1. Download mimic and extract.
  2. Copy minic.js from deploy folder to {your site folder}/mimic
  3. Create mimic.htm in the same folder with a following content:
    <script src="mimic.js"></script>
  4. Open developer console and write js for testing. For example, if you have enabled test resource you could write following commands:
    var request = new XmlRpcRequest("/{your site folder}/api", 'services_test.test');
    request.addParam('1');
    var response = request.send();
    alert(response.parseXML());
    

I assumed that http://localhost/{your site folder}/api is your XMLRPC endpoint.

Also xmlrpc function could be

Posted by dealancer on January 5, 2012 at 1:08pm

Also xmlrpc function could be run for testing in devel/php, see example:

$result = xmlrpc($url, array(
'services_test.test' => array('1'),
));
dpm($result);

Here is a code snippet that

Posted by dealancer on January 5, 2012 at 1:53pm

Here is a code snippet that logs in and creates test node:

$result = xmlrpc($url, array(
'user.login' => array($login, $password),
));
$options['headers']['Cookie'] = $result['session_name']. '=' . $result['sessid'];
$data=array('type'=>'page', 'title'=>'Test', 'body'=>'test');
$result = xmlrpc($url, array(
'node.create' => array($data),
), $options);

Well, here is a code that

Posted by dealancer on January 7, 2012 at 11:44am

Well, here is a code that logs in, posts request to the test service and logs out.

<?php
$url
= 'http://localhost/drupal/drupal7/api';
$login = 'admin';
$password = 'admin';

// Login to the remote website via XML RPC
$result = xmlrpc($url, array(
'user.login' => array($login, $password),
));
// Save session
$options['headers']['Cookie'] = $result['session_name']. '=' . $result['sessid'];

// Get new sid
$result = xmlrpc($url, array(
'services_test.test' => array(1),
),
$options);

dpm($result);

// Log out
$result = xmlrpc($url, array(
'user.logout' => array(),
),
$options);
?>

thanks !

Posted by stonevo on March 14, 2012 at 4:46am

It looks great. Thanks dealancer.

Drupal - The modern Lego game

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /