Install soap4r

The soap4r module is bundled with modern versions of Ruby. The latest version is also available as a Ruby Gem or as a download from the soap4r web site. For package based platforms (e.g. Ubuntu, CentOS, etc.) check if a package exists before installing from a Ruby Gem or download.

Using soap4r can be used to create a service proxy, from a WSDL document, which provides an interface to the web service. Using the methods provided by the service proxy the service can be used as though it was a local resource.

For example: using WSDbfetch to get fasta formatted sequence for the UniProtKB protein ALK1_HUMAN

Load the soap4r library:

require 'soap/wsdlDriver'

Get the service proxy for the service:

# URL for the service WSDL
wsdl = ''
# Get the object from the WSDL
dbfetchSrv =

For debugging it is useful to see the SOAP messages being passed between the client and the server:

dbfetchSrv.wiredump_dev = STDOUT

Get the data from the service and print it:

puts dbfetchSrv.fetchData("UNIPROT:ADH1A_HUMAN", "fasta", "raw")

All the methods in the WSDbfetch service take simple strings as arguments. For complex data types such as those used in the WSFasta service nested hash data structures are used to represent the type.

For example: submitting a job to WSFasta:

# Query sequence
seq = ">Q8E5Q5_STRA3
# Get the object from the WSDL
fastaSrv =
# Set the parameters for the job
params = {}  
params['program'] = 'ssearch'
params['database'] = 'swissprot'
params['email'] = 'your@email'
params['async'] = 1
# Build the data structure
data = [{'type'=>'sequence', 'content'=>seq}]
# Submit the job
jobId = fastaSrv.runFasta(params, data)
puts jobId

Given the job identifier we poll until the job completes:

# Use the job identifier to check the status of the job
status = 'RUNNING'
while status=='RUNNING'
  sleep 10 
  status = fastaSrv.checkStatus(jobId)
  puts status

And if the job completed successfully, retrieve the result:

# When finished get the result
if status=='DONE'
  puts fastaSrv.polljob(jobId, 'tooloutput')  


Sample Clients

Most SOAP Web Services at EMBL-EBI have sample clients which provide command-line access to the service and example code. For Ruby these clients are based on soap4r.

Document/literal SOAP

RPC/encoded SOAP

Service Sample client
WSDbfetch wsdbfetch.rb

Up Ruby Contents Contents
tutorials/06_programming/ruby/soap/soap4r.txt · Last modified: 2011/07/26 07:43 by hpm