On consuming web services

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
texas-bronius's picture

This is all great for exposing Drupal as web services, but consuming web services still eludes me. For instance, I have an LDAP directory exposed via SOAP and want to build a client to search and list directory entries from within Drupal. Am I better off making a homegrown "php snippet" solution, or am I missing something that the Services module already provides?

Comments

Services, in its current

snelson's picture

Services, in its current form, was made to provide services, but that doesn't mean that it can't evolve to include client capabilites.

There could be a soap.module that would hook into services for its server capabilities, and also include functions to connect to outside services. Or, perhaps a SOAP project package would include both a soap_client.module and soap_server.module. Someone just needs to build it.

Scott

SOAP module sponsor

steveparks's picture

Hi

I'm willing to sponsor development of a SOAP module, with both the client and server modules as described above.

I have a need to link a Drupal ecommerce site to another system via SOAP, with product and stock data being pulled into the drupal site one way, and sales information being pushed back the other way.

cheers
Steve

=======
Steve Parks
WunderRoot
http://www.wunderroot.com

Consuming WebService, creating local nodes

texas-bronius's picture

Steve, Did you get anywhere with this a couple years go?
I am looking at the new Feeds module with great interest, because it sounds like I am trying to do exactly what you wrote, and Feeds does it, but not for webservices (from what I can tell). That said, it looks like a hook or plugin could be written to handle GETs.. I don't know yet.

I agree

kehan's picture

Being able to consume SOAP services does make a lot of sense - how do we do it.
Cheers,
Kehan

SOAP

hal98se's picture

.NET uses WSDL (web services description language) - you can run the WSDL exe file and supply the url of the web service as an argument and it will automatically build apis to program against for web services, is there anything like this for php?

The NuSOAP library for PHP

ebeyrent's picture

The NuSOAP library for PHP will automatically handle SOAP transactions for you if you supply the WSDL.

$client = new nusoap_client('http://www.foo.com/server.php?wsdl', true);
$proxy = $client->getProxy();
$result = $proxy->someMethod();

if(! $err = $proxy->getError()) {
echo $result;
}
else {
echo $err;
}

NuSphere PhpEd

texas-bronius's picture

I use NuSphere PhpEd for my php development-- really nice debugger built in! It's a commercial product. Its wsdl discovery goes so far as to make code stubs based on wsdl url, but I don't recall if it does "smart code completion" for web service methods (I wouldn't put it past them..)

There is a SOAP module now

mlncn's picture

http://drupal.org/project/soapclient

It can use PHP5's implementation or the more powerful NuSOAP. (I haven't used it yet.)

benjamin, Agaric Design Collective

benjamin, agaric

Not able to use SOAP......

skctek's picture

Hi

I am new to drupal and I am using the SOAP module in my project. I saved module in the directory "C:\Program Files\xampp\htdocs\webservices\sites\all\modules\soap_server\nusoap\lib" onlocal host and in soap_server_test.php I have following...
<?php
// Pull in the NuSOAP code
// Create the client instance

// TODO Set the paht of wsdl
$wsdl = "http://localhost/webservices/services/soap?wsdl";
// N.B: allow anonymous user to access services.
$client = new SoapClient($wsdl,
array(
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
)
);
// Set this variable TRUE if we enable use session on services settings.
DEFINE('USE_SESSION', FALSE);
$user = NULL;

$client->debug_flag=true;
// $client->proxyhost = 'localhost';
// $client->proxyport = 8080;
// print_r($client);
// Call the SOAP method

// Set method parameters
/*
* node.load params are
* 1- nid => int
* 2- fields => array (optional)
* Let we call methos twice with & without fields
* then we have $param1 & $param2
*/
if (USE_SESSION) {
$param['sessid'] = '1234534534dfsf';
}
$param['username'] = 'user';
$param['password'] = 'password';
echo 'Call user.login with optional params

---------------------------------------------------------------';
$user = $client->__soapCall('user.login', $param);
echo '

';print_r($user);echo '

';
//set $fields this is an optional arg
$fields = array('nid', 'title', 'type');
// $fields = array('title');
$key = '42b61dd05eb2cea16614a4270ce7cbd6';

if (USE_SESSION) {
$param1['sessid'] = $user[0]->value;
$param2['sessid'] = $user[0]->value;
}
// Set $nid = nid you want to load it.
$param1['nid'] = $nid; //Set nid
$param2['nid'] = $nid;
$param2['fields'] = $fields;

//To load node information (avoid access denied).
// Set USE_SESSION to be TRUE
// Login with account that have a permission to load the node.

// First case
echo 'Call node.load without optional params

------------------------------------------------------------------';
// $result = $client->call('node.load', $key, $param1);
$result = $client->__soapCall('node.get', $param1);
echo '

';print_r($result);echo '

';

// Second caseccess denied.
echo 'Call node.load with optional params

---------------------------------------------------------------';
$result = $client->__soapCall('node.get', $param2);
echo '

';print_r($result);echo '

';

In services when I click on WSDL it navigate me to http://localhost/webservices/index.php?wsdl which is simply the home page.I dont know what to do. Please some one help me out and please chaek if the line in code..$wsdl = "http://localhost/webservices/services/soap?wsdl"; is correct or wrong.

Thank you in advance.

Can somebody show me a working example?

peterjjohnson's picture

I am running Drupal core 6.17, Services 6.2.2, Key Authentication 6.2.2, XMLRPC Server 6.2.2 and Node Service 6.2.2. I've unchecked the boxes for Key and Session ID in the Services Settings tab, but all I get when I try the following code is "Access Denied". Same if I try 'echo.echo' as the method, from the "Echo Service" example.

<?php
require_once("/var/www/htdocs/sites/all/libraries/xmlrpc-3.0.0.beta/lib/xmlrpc.inc");
$nid = 1;
$nid = new xmlrpcval($nid, "int");
$m = new xmlrpcmsg('node.get', array($nid, new xmlrpcval(array(), "array"))
  );
$c = new xmlrpc_client('/services/xmlrpc', 'localhost', 80);
$r = $c->send($m);
print_r($r);
?>

Can somebody point me at an example that works?
Thanks in advance

Example of Keys on and Session on

ericpai's picture

I hope this helps you. I'm using it with Keys and session on.
Set permission for anonymous user for node_service module -> load node data
<?
$server = 'http://my.server.com/services/xmlrpc';
// Get xmlrpc result.
$xmlrpc_result = xmlrpc($server, 'system.connect');
$sid = $xmlrpc_result['sessid'];
echo 'sid= '.$sid;
?>

<?
if($error = xmlrpc_error()){
if($error->code <= 0){
$error->message = t('Outgoing HTTP request failed because the socket could not be opened.');
}

drupal_set_message(t('Operation failed because the remote site gave an error: %message (@code).',
array(
'%message' => $error->message,
'@code' => $error->code
)
)
);

}
?>
<?
$api_key = '166f4e6d2005129c48a3d11409df8599';
$timestamp = (string) time();
$nonce = user_password();
$domain = 'myclientsite.com';
// Create secure hash using your api key.
$hash = hash_hmac('sha256', $timestamp .';'.$domain .';'. $nonce .';'.'node.get', $api_key);

$nid = 35;
// Get a node from the remote server.
$xmlrpc_result = xmlrpc($server, 'node.get', $hash, $domain, $timestamp, $nonce, $sid, '35', array('title', 'body'));
print_r($xmlrpc_result);
?>
<?
if($error = xmlrpc_error()){
if($error->code <= 0){
$error->message = t('Outgoing HTTP request failed because the socket could not be opened.');
}

drupal_set_message(t('Operation failed because the remote site gave an error: %message (@code).',
array(
'%message' => $error->message,
'@code' => $error->code
)
)
);

}
?>

There are permission you need

ayb's picture

There are permission you need to set. Click 'load node data' and 'admin service'.
yoursite.com/admin/user/permission.

There are a lot of options

ThomWestley's picture

There are a lot of options that Drupal services offer but we, as services consumers don't even know of their existance. While working for an ez saver database, I needed to use some Drupal services that I had no idea they were implemented in the platform and I ended up having to work a lot more than I actually should. Forums are a food way to find out about these services and it's worth to ask before getting started.

subscribing

jejk's picture

subscribing

my opinion is that the

CamdenRandel's picture

My opinion is that the solution you can find first is the best. If the services module does offer client services, you might end up wasting more time learning how to use them than creating a php snippet from scrap.
Maryland water damage

ah0's picture

hey guys, I think the solution to all these is this new mod,
It handles REST , SOAP and works hand-in-hand with the Rules module too
really nice UI too.

http://drupal.org/project/wsclient

subscribing

made4w3's picture

subscribing

Services

Group organizers

Group categories

Group notifications

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