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

Step2. Create now client and set the WSDL as "true".

Step3. Send the request using call() method
mixed call (string $operation, [mixed $params = array()], [string $namespace = ''], [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 ''. This will cause fault from the server.
Here my test request,
$result = $client->call('yourMethod',array('parameters'=> $yourType),

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)...

No comments: