spacer
spacer

PHP SOAP

Introduction

PHP SOAP is included with PHP 5 making it the simplest tool kit to set-up.

Creating a Service Proxy

For 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 (dbfetch_php_soap.php):

# URL for the service WSDL
$wsdlUrl = 'http://www.ebi.ac.uk/ws/services/WSDbfetch?wsdl';
 
try {
  // Get a service proxy from the WSDL
  $proxy = new SoapClient($wsdlUrl);
 
  // Call a method on the service via the proxy
  $result = $proxy->fetchData('UNIPROT:ADH1A_HUMAN', 'fasta', 'raw');
  echo $result;
}
catch(SoapFault $ex) {
  echo 'Error: ';
  if($ex->getMessage() != '') echo $ex->getMessage();
  else echo $ex;
  echo "\n";
}

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 runWUBlast method (wublast_php_soap.php):

  // 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);
  echo "$jobId\n";

The runWUBlast method returns a job identifier which can be used with the checkStatus method to get the status of the job (e.g. RUNNING, DONE or ERROR) and the poll method to get the results of the job:

  // Poll till job finishes
  $status = 'PENDING';
  while(strcmp($status, 'RUNNING') == 0 || strcmp($status, 'PENDING') == 0) {
    $status = $proxy->checkStatus($jobId);
    echo "$status\n";
    if(strcmp($status, 'RUNNING') == 0 || strcmp(status, 'PENDING') == 0) {
      sleep(10);
    }
  }
 
  // Get the result
  $result = $proxy->poll($jobId, 'tooloutput');
  echo $result;

Sample Clients

Most 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 PHP-SOAP.

Document/literal SOAP

RPC/encoded SOAP

Service Sample client
WSDbfetch wsdbfetch_cli_php_soap.php


Up PHP Contents Contents
 
tutorials/06_programming/php/soap/php-soap.txt · Last modified: 2011/07/26 07:36 by hpm
spacer
spacer