![]() |
Table of Contents
SOAP::LiteInstallationThe SOAP::Lite modules can be installed by:
For an overview of the how to install a module see Installing Perl Modules. Note: check the version of SOAP::Lite before installing, there are known issues with some versions. Accessing a ServiceThere are three ways to use SOAP::Lite to access a SOAP Web Service:
Dynamic Interface from a WSDLSOAP::Lite->service($WSDL)
The service proxy object, which is used to access the service operations, can be generated from a WSDL using the For example: fetching the WAP_RAT UniProtKB entry using WSDbfetch (examples/SOAP/SOAP-Lite/dbfetch_soaplite.pl) # SOAP::Lite module use SOAP::Lite; # WSDbfetch WSDL URL my $WSDL = 'http://www.ebi.ac.uk/ws/services/WSDbfetch?wsdl'; # Default option values my ($query, $format, $style) = ('uniprot:wap_rat', 'fasta', 'raw'); # Create a service proxy from the WSDL. Specifying a SOAP fault handler which maps a fault to a die. my $soap = SOAP::Lite ->service($WSDL) ->on_fault(sub { # SOAP fault handler my $soap = shift; my $res = shift; # Map faults to exceptions if(ref($res) eq '') { die($res); } else { die($res->faultstring); } return new SOAP::SOM; } ); # Perform the query my $result = $soap->fetchData($query, $format, $style); # Output the result print $result; Exercise 1: WSDbfetch with SOAP::LiteThe WSDbfetch web service (http://www.ebi.ac.uk/Tools/webservices/services/dbfetch) provides the same basic functionality as dbfetch, but through a SOAP interface. Using the example WSDbfetch client (examples/SOAP/SOAP-Lite/dbfetch_soaplite.pl) as a guide, use the service to fetch the UniProtKB entries with the accessions: P13569, P26361 and P35071, in fasta format. Sample solution: solutions/SOAP/SOAP-Lite/q1_dbfetch_soaplite.pl Static Interface from a WSDL
SOAP::Lite includes a utility ( stubmaker.pl http://www.ebi.ac.uk/ws/services/WSDbfetch?wsdl
This generates a Perl module (.pm) named after the Web Service described in the WSDL (e.g. The generated Perl module is used by loading the module and creating an instance of the class named for the service. For example for the WSDbfetch service (examples/SOAP/SOAP-Lite/dbfetch_soaplite_stubs.pl): # Load generated stubs use WSDBFetchServerService; # Get service proxy my $soap = new WSDBFetchServerService->new(); # Add a fault handler to map a fault to a die $soap->on_fault( sub { # SOAP fault handler my $soap = shift; my $res = shift; # Map faults to exceptions if(ref($res) eq '') { die($res); } else { die($res->faultstring); } return new SOAP::SOM; } ); # Parameter values my ($query, $format, $style) = ('uniprot:wap_rat', 'fasta', 'raw'); # Perform the query my $result = $soap->fetchData($query, $format, $style); # Output the result print $result; Exercise 2: Generate stubs
Generate static stubs for WSDbfetch using Exercise 3: WSDbfetch meta-dataThe WSDbfetch service includes a number of meta-data methods which provide information about the service such as the names of the databases available, and the formats and styles which can be used with each database (see http://www.ebi.ac.uk/Tools/webservices/services/dbfetch).
Starting from the stubs based client (examples/SOAP/SOAP-Lite/dbfetch_soaplite_stubs.pl), use the Sample solution: solutions/SOAP/SOAP-Lite/q3_dbfetch_soaplite_stubs.pl Direct SOAP Calls
If a WSDL is not available for the Web Service, then direct calls can be made to the service using the # Load the SOAP library use SOAP::Lite; # Service details my $NAMESPACE = 'http://www.ebi.ac.uk/ws/services/WSDbfetch'; my $ENDPOINT = 'http://www.ebi.ac.uk/ws/services/WSDbfetch'; # Create interface to the service my $soap = new SOAP::Lite(uri => $NAMESPACE, proxy => $ENDPOINT); # Add a fault handler to map a fault to a die $soap->on_fault( sub { # SOAP fault handler my $soap = shift; my $res = shift; # Map faults to exceptions if ( ref($res) eq '' ) { die($res); } else { die( $res->faultstring ); } return new SOAP::SOM; } ); # Parameter values my ($query, $format, $style) = ('uniprot:wap_rat', 'fasta', 'raw'); # Perform the query my $result = $soap->call('fetchData' => $query, $format, $style); # Output the result print $result->result; SOAP::Lite->uri()->proxy()
While
For example: the # Load modules use SOAP::Lite; # EB-eye namespace and endpoint (from WSDL) my $NAMESPACE = 'http://webservice.ebinocle.ebi.ac.uk'; my $ENDPOINT = 'http://www.ebi.ac.uk/ebisearch/service.ebi'; # Chunk size for getting results my $chunkSize = 50; # Query details my ( $domain, $query ) = ( 'uniprot', 'azurin' ); # Create the service proxy and define a fault handler my $soap = SOAP::Lite->uri($NAMESPACE)->proxy($ENDPOINT)->on_fault( sub { # SOAP fault handler my $soap = shift; my $res = shift; # Map faults to exceptions if ( ref($res) eq '' ) { die($res); } else { die( $res->faultstring ); } return new SOAP::SOM; } ); # Get identifiers matching the query my ($response); # First find out how many $response = $soap->getNumberOfResults( $domain, $query ); my $numEntries = $response->valueof('//getNumberOfResultsResponse/numberOfResults'); print "$numEntries entries found for $query in $domain\n"; # Loop over results getting and printing each chunk. for ( my $start = 0 ; $start < $numEntries ; $start += $chunkSize ) { # Get the chunk $response = $soap->getResultsIds( $domain, $query, $start, $chunkSize ); my (@idList) = $response->valueof('//getResultsIdsResponse/arrayOfIds/string'); # Print each ID foreach my $id (@idList) { print $id, "\n"; } } Exercise 4: EB-eyeThe EB-eye web service (http://www.ebi.ac.uk/Tools/webservices/services/eb-eye) provides a method for searching a broad selection of the databases available at EMBL-EBI. As well a search functionality it also provides methods for exploring the data using links based on the cross-references present in the data. Using the example EB-eye client (examples/SOAP/SOAP-Lite/ebeye_soaplite.pl) as a guide, use the EB-eye to find the number of entries in EMBL-Bank Coding Sequence (emblcds) which contain the term “CFTR”. Sample solution: solutions/SOAP/SOAP-Lite/q4_ebeye_soaplite.pl Exercise 5: EB-eye meta-dataLike WSDbfetch the EB-eye web service provides methods to get details of the available search domains, the fields within the domains and details of cross-references.
Starting from the example EB-eye client (examples/SOAP/SOAP-Lite/ebeye_soaplite.pl) get the list of available domains ( Sample solution: solutions/SOAP/SOAP-Lite/q5_ebeye_soaplite.pl Complex Data StructuresIf the service call requires a complex input type this needs to be built. For example to submit a job to the FASTA (SOAP) service. Create the SOAP::Data objects to be passed to the service (examples/SOAP/SOAP-Lite/fasta_soaplite.pl): # Build parameters structure my $params = SOAP::Data->name('parameters' => \SOAP::Data->value( SOAP::Data->name('program' => 'fasta'), # Program to perform search SOAP::Data->name('database' => [ # Database(s) to search SOAP::Data->type('string' => 'pdb')->name('string')->attr({'xmlns' => ''}) ]), SOAP::Data->name('scores' => 10), # Number of hit summary scores SOAP::Data->name('alignments' => 10), # Number of hit alignments SOAP::Data->name('stype' => 'protein'), # Sequence type SOAP::Data->name('sequence' => $query_sequence) # Query sequence ) ); # Submit the job print STDERR 'Sumbit job...', "\n"; my $jobid = $soap->run( SOAP::Data->name('email' => $email)->attr({'xmlns' => ''}), SOAP::Data->name('title' => $title)->attr({'xmlns' => ''}), SOAP::Data->name('parameters' => $params)->attr({'xmlns' => ''}) )->result; print STDERR 'Job ID: ', $jobid, "\n"; See Complex SOAP::Lite requests - my rules for SOAP::Sanity! for a guide to building the complex structures required by some services. Exercise 6: FASTA (SOAP) with SOAP::LiteAnalytical tools may take sometime to complete so these tools need to be run using an asynchronous method. Where the submission returns a job identifier which can be then used to check on the status of the job, and once it completes retrieve the results. The FASTA (SOAP) service (http://www.ebi.ac.uk/Tools/webservices/services/sss/fasta_soap), which uses the FASTA suite to perform a sequence similarity search is one service that requires this approach. Examine the example client (examples/SOAP/SOAP-Lite/fasta_soaplite.pl) and note the “run”, “getStatus” and “getResult” work flow. Using the example client as a guide, use FASTA (SOAP) to perform a FASTA search with UniProtKB CFTR_MOUSE against UniProtKB/SwissProt. Sample solution: solutions/SOAP/SOAP-Lite/q6_fasta_soaplite.pl Exercise 7: FASTA (SOAP) meta-data
The FASTA (SOAP) service can return the result in a number of formats, modify your client to use the Sample solution: solutions/SOAP/SOAP-Lite/q7_fasta_soaplite.pl SOAP Message Trace
It is useful when debugging a client to be able to see the actual SOAP messages exchanged. SOAP::Lite provides a SOAP::Lite->import(+trace => qw(debug)); SOAP Faults
If a SOAP fault handler ( # Check for fault and map into an exception. if($soap->call->fault) { die $soap->call->faultstring; }
Normally the SOAP fault handler ( # Add a fault handler to map a fault to a die $soap->on_fault( sub { # SOAP fault handler my $soap = shift; my $res = shift; # Map faults to exceptions if ( ref($res) eq '' ) { die($res); } else { die( $res->faultstring ); } return new SOAP::SOM; } ); HTTP ProxiesIn some environments it is necessary to configure an HTTP proxy before a client can connect to external services. SOAP::Lite supports two ways to set proxy information:
See Proxies for more details regarding LWP support for HTTP proxies. HTTP User-Agent
HTTP clients usually provide information about what they are, this allows services to handle specific clients differently if necessary, and gives service providers information about how their services are being used. By default SOAP::Lite sets the HTTP User-Agent header (see RFC2616 section 14.43) to something like # Modify the user-agent to add a more specific prefix (see RFC2616 section 14.43) $soap->transport->agent("Example-Client/1.0 ($OSNAME) " . $soap->transport->agent()); Note: while the HTTP specification does not define a limit on the size of HTTP headers, web server implementations often do limit the maximum size of an HTTP header to 8KB or 16KB. If the server limit for an HTTP header is exceeded a “400 Bad Request” will be returned by the server. HTTP Compression
SOAP::Lite provides support for on the fly compression of HTTP requests and decompression of HTTP responses (SOAP::Lite COMPRESSION), which can save bandwidth and improve the performance of data transfers between the client and the web service. To enable HTTP compression add the my $soap = SOAP::Lite->proxy( $ENDPOINT, timeout => 6000, # HTTP connection timeout options => { # HTTP compression (requires Compress::Zlib) compress_threshold => 1024, # Prevent request compression. }, )->uri($NAMESPACE);
Handling for compressed HTTP responses is enabled if the
If the web service does not support HTTP request compression and returns a HTTP status code of “415 Unsupported Media Type”, the request will be retried without compression. Note that not all web services return the required status for this case, and for those services it is necessary to disable HTTP request compression by using a large Sample ClientsMost SOAP Web Services at EMBL-EBI have sample clients which provide command-line access to the service and example code. For Perl most of the clients are based on SOAP::Lite. Document/literal SOAP
RPC/encoded SOAP![]() |