If you are new to the PHP and NuSOAP, my previous posting would be helpful too.
Here is the simple example for the getStatus operation,
// Pull in the NuSOAP code
require_once('../lib/nusoap.php');
$client = new soapclient("http://your.service.location:8080/axis2/services/JobSubmissionService?wsdl",true);
$TaskId = array('clusterID' => "403", 'jobID' =>"0");
$taskId = array('TaskId' => $TaskId);
$getStatus = array('taskId'=>$TaskId);
$result = $client->call('getStatus',array('parameters'=> $getStatus),
'http://jobsubmissionservice.ogce.org/xsd','',false,null,'rpc','encoded');
if ($client->fault){
echo 'Fault';
}
print_r($result);
Wednesday, July 2, 2008
Creating a PHP client of the Web Service(Axis2) using NuSOAP
You can download NuSOAP library from the NuSOAP project is hosted by SourceForge. It is a package of php files you can keep in your php document directory or in a separate directory. In my case, I copied /lib directory from the NuSOAP project under /usr/local/apache2/htdocs/ which is default location of documents for the apache2 server. Then, copied /sample directory of the NuSOAP project under the same directory, /usr/local/apache2/htdocs/. You can download document from the same site. It contains nusoap method summary. Now, it's time to build a WS client..
Step1. pull in the NuSOAP code into your php source code
require_once('../lib/nusoap.php');
Step2. Create now client and set the WSDL as "true".
soapclient("http://service.location.url:8080/axis2/services/YourTargetService?wsdl",true);
Step3. Send the request using call() method
mixed call (string $operation, [mixed $params = array()], [string $namespace = 'http://tempuri.org'], [string $soapAction = ''], [mixed $headers = false], [boolean $rpcParams = null], [string $style = 'rpc'], [string $use = 'encoded'])
Please note that if you don't specify the namespace, your outgoing SOAP message will include SOAP Body with namespace of 'http://tempuri.org'. This will cause fault from the server.
Here my test request,
$result = $client->call('yourMethod',array('parameters'=> $yourType),
'http://yourservice.namespace.org/xsd','',false,null,'rpc','encoded');
Also, the $params which is arguments passed to the service is the element defined in the wsdl:message. If your service has hierarchical data type structure, you need to track down your WSDL carefully.
Step4. see the result..
I just used print_r($result)...
Step1. pull in the NuSOAP code into your php source code
require_once('../lib/nusoap.php');
Step2. Create now client and set the WSDL as "true".
soapclient("http://service.location.url:8080/axis2/services/YourTargetService?wsdl",true);
Step3. Send the request using call() method
mixed call (string $operation, [mixed $params = array()], [string $namespace = 'http://tempuri.org'], [string $soapAction = ''], [mixed $headers = false], [boolean $rpcParams = null], [string $style = 'rpc'], [string $use = 'encoded'])
Please note that if you don't specify the namespace, your outgoing SOAP message will include SOAP Body with namespace of 'http://tempuri.org'. This will cause fault from the server.
Here my test request,
$result = $client->call('yourMethod',array('parameters'=> $yourType),
'http://yourservice.namespace.org/xsd','',false,null,'rpc','encoded');
Also, the $params which is arguments passed to the service is the element defined in the wsdl:message
Step4. see the result..
I just used print_r($result)...
Subscribe to:
Posts (Atom)