Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in R, how can I call a web service if I have WSDL description of it? (consume web service)

I am not an expert of SOAP and WSDL but I have Perl code which I would like to port to R.

The Perl code looks like this (from https://www.pharmgkb.org/resources/downloads_and_web_services.jsp):

use SOAP::Lite;
import SOAP::Data 'type';

sub main {
  my $argcount = scalar (@ARGV);
  if ($argcount != 1) {
    print "usage: diseases.pl <PharmGKB accession id>\n";
    exit -1;
  }

  # make a web services call to server
  my $call = SOAP::Lite
    -> readable (1)
    -> uri('PharmGKBItem')
    -> proxy('http://www.pharmgkb.org/services/PharmGKBItem')
    -> searchDisease($ARGV[0]);

  if ($call->fault) {
    print $call->faultcode . ": " . $call->faultstring . "\n";
  } else {
    my $result = $call->result;

The read things about rsoap and SSOAP packages but did not get any nice info. What I need is full support, such as call the service and provide libraries to parse the output. I prefer some libraries rather then raw coding. I am good with XML package and not very good with RCurl. I am correct in thinking that there is no good and current (actively maintained) support in R for this?

like image 280
userJT Avatar asked Mar 27 '12 14:03

userJT


People also ask

Can we create web service using WSDL?

Typically, you start from WSDL to build your web service if you want to implement a web service that is already defined either by a standard or an existing instance of the service.

How is WSDL used in the context of Web services?

WSDL is an XML file that defines and describes the services that are available in the web service of interest. It describes the naming of services, the specifications and structure of the response sent back. The services in the WSDL are described as a compilation of network ports/endpoints.

How do you call a web service?

To call a Web service programmaticallyUse the Web reference name (or server name) as the namespace, and the name of its . WSDL file (or the service name) as the proxy class. The following code example calls a Web service method to get a string value. Web service variable names and syntax are highlighted.


1 Answers

Checkout the SSOAP package on OmegaHat. It's compatible with both S and R. It even has an genSOAPClientInterface function for generating the available Operations in the WSDL as R functions and generating the associated S4 classes for all of your data types described in the WSDL. It leverages XML and RCurl (both of which were created by the same author). He provides a directory full of examples and pretty useful PDF documentation.

I had a few problems with it when using my WSDL (and am still using modified code to get it to work), but the author of the package is extremely helpful and responsive to bug reports, if you run into issues.

like image 78
Jeff Allen Avatar answered Sep 28 '22 07:09

Jeff Allen