![]() |
Table of Contents
nuSOAPIntroductionThe nuSOAP library supports PHP 4, and is pure PHP code, making it useful for environments where wide PHP version support is required or where binary extensions cannot be installed. The standard nuSOAP library (0.7.2) contains a namespace collision when used in PHP 5, so for PHP 5 use the modified nusoap-for-php5 or the latest nuSOAP 0.7.3. Creating a Service ProxyFor SOAP services providing a WSDL document, a service proxy object can be generated from the WSDL at runtime, allowing access to the current service interface. For example using the WSDbfetch service: # Load the nuSOAP library require_once('lib/nusoap.php'); # URL for the service WSDL $wsdlUrl = 'http://www.ebi.ac.uk/ws/services/WSDbfetch?wsdl'; # Get the client object from the WSDL if(class_exists('soapclientNusoap')) { // nusoap-for-php5 $client = new soapclientNusoap($wsdlUrl, true); } elseif(class_exists('nusoap_client')) { // nuSOAP 0.7.3 $client = new nusoap_client($wsdlUrl, true); } else { // nuSOAP 0.7.2 or earlier (assumes PHP SOAP not available) $client = new soapclient($wsdlUrl, true); } $err = $client->getError(); if($err) trigger_error($err, E_USER_ERROR); # Get service proxy from the client object $proxy = $client->getProxy(); $err = $proxy->getError(); if($err) trigger_error($err, E_USER_ERROR); # Call a method on the service via the proxy $result = $proxy->fetchData('UNIPROT:ADH1A_HUMAN', 'fasta', 'raw'); # Check for errors $err = $proxy->getError(); if($err) trigger_error($err, E_USER_ERROR); # Print result echo $result; Complex Types
The methods in the WSDbfetch all use simple string parameters. Many of the other EBI services use more complex input structures. For example WSWUBlast requires a structure containing the various parameters and the input sequence to be passed to the // Input parameters $params = array( 'email' => 'email@example.org', 'async' => TRUE, 'program' => 'blastp', 'database' => 'swissprot' ); // Input data $data = array( array( 'type' => 'sequence', 'content' => <<<EOF >Q8E5Q5_STRA3 MKLSKRYRFWQKVIKALGVLALIATLVLVVYLYKLGILNDSNELKDLVHKYEFWGPMIFI VAQIVQIVFPVIPGGVTTVAGFLIFGPTLGFIYNYIGIIIGSVILFWLVKFYGRKFVLLF MDQKTFDKYESKLETSGYEKFFIFCMASPISPADIMVMITGLSNMSIKRFVTIIMITKPI SIIGYSYLWIYGGDILKNFLN EOF ) ); // Submit the job $jobId = $proxy->runWUBlast($params, $data); // Check for errors $err = $proxy->getError(); if($err) trigger_error($err, E_USER_ERROR); // Print the job identifier echo "$jobId\n";
The // Poll till job finishes $status = 'PENDING'; while(strcmp($status, 'RUNNING') == 0 || strcmp($status, 'PENDING') == 0) { $status = $proxy->checkStatus($jobId); $err = $proxy->getError(); if($err) trigger_error($err, E_USER_ERROR); echo "$status\n"; if(strcmp($status, 'RUNNING') == 0 || strcmp(status, 'PENDING') == 0) { sleep(10); } } // Get the result $result = $proxy->poll($jobId, 'tooloutput'); $err = $proxy->getError(); if($err) trigger_error($err, E_USER_ERROR); echo $result; ExamplesThe complete source code for these examples as command-line programs is available: Sample ClientsMost SOAP Web Services at EMBL-EBI have sample clients which provide command-line access to the service and example code. For PHP some of the clients are based on nuSOAP. RPC/encoded SOAP![]() |