NuSoap Newbie

Hi Guys,

I have to access a SOAP webservice and have been looking at NuSOAP

It all seems easy enough however ( Always a However)

here is my code


require_once('lib/nusoap.php');
$c = new nusoap_client('http://url.com/WebService.asmx?WSDL',true);
$client = $c->call('getAllClients');
print_r($client);

This returns all the clients to the screen

if i view the source of this it is XML

doens anyone know how i can somehow parse this returned array into vars?

Any help will be great

K-

It’s a little hard to do this without an XML sample, but [fphp]SimpleXMLElement[/fphp] would be good starting point.

this is what it returns, if i view the source



   [FONT=&quot]Array[/FONT]
  [FONT=&quot]([/FONT]
  [FONT=&quot]    [getAllClientsResult] => <NewDataSet>[/FONT]
  [FONT=&quot]  <Table>[/FONT]
  [FONT=&quot]    <name>Kenny</name>[/FONT]
  [FONT=&quot]    <Surname>France</surname>[/FONT]
  [FONT=&quot]  </Table>[/FONT]
      [FONT=&quot]<Table>[/FONT]
  [FONT=&quot]    <name>Kenny2</name>[/FONT]
  [FONT=&quot]    <Surname>France2</surname>[/FONT]
  [FONT=&quot]  </Table>[/FONT]
   
  [FONT=&quot]<Table>[/FONT]
  [FONT=&quot]    <name>Kenny3</name>[/FONT]
  [FONT=&quot]    <Surname>France3</surname>[/FONT]
  [FONT=&quot]  </Table>[/FONT]
   
  </NewDataSet>)

```php


and simple XML outputs this error

[B]Fatal error[/B]: Uncaught exception 'Exception' with message 'SimpleXMLElement::__construct() expects parameter 1 to be string, array given' in /home/username/public_html/soap/soap_client.php:17 Stack trace: #0 /home/username/public_html/soap/soap_client.php(17): SimpleXMLElement-&gt;__construct(Array) #1 {main} thrown in


K-

Give this a bash. :slight_smile:


<?php
require_once('lib/nusoap.php');
$client = new nusoap_client('http://url.com/WebService.asmx?WSDL',true);
$response = $client->call('getAllClients');
$xml = new SimpleXMLElement($response['getAllClientsResult']);
foreach($xml->Table as $user){
    printf("&#37;s %s\\r\
", $user->name, $user->Surname);
}
?>

thanks anthony

but i get the same error

Kenny

Rather than print_r, can you var_dump the response please?

Why not use PHP5’s inbuilt extension SOAP?
It’s very simple to use than NuSoap, I bet.

Hi PHPyco

Do you possible have an example on how to use PHP5’s extension?

i have no experiance with soap unfortunatly, but NuSoap looked pretty simple

Thanks

Kenny

NuSOAP is bringing back the data you require no? Switching now would be fruitless, your problem lies in the fact you don’t know how to access the data returned…

Hi Anthony

Here is the example
(I will remove once this is sorted)

http://www.server98.co.za/soap/soap_client.php

and here is the service

http://www.mytracer.co.za/MyTracerWebService.asmx

and here is the code



$c = new nusoap_client('http://www.mytracer.co.za/MyTracerWebService.asmx?WSDL',true);
$client = $c->call('getAllClients');

print var_dump($client);


thanks

Kenny

here is one tutorial regarding PHP5’s SOAP extension:
http://devzone.zend.com/article/689

Then this, should work.


<?php
require_once('lib/nusoap.php');
$client = new nusoap_client('http://url.com/WebService.asmx?WSDL',true);
$response = $client->call('getAllClients');
$xml = new SimpleXMLElement((string)$response['getAllClientsResult']);
foreach($xml->Table as $user){
    printf("&#37;s\\r\
", $user->debtorname);
}
?>

A case of beer for Anthony

You are a 100% star

Thanks for your efforts

K-

PS how can i edit the post to remove urls?

An easier approach using PHP5’s SOAP extension:

<?php
$client = new SoapClient("http://url-to-wsdl.com");
print_r($client->getAllClients()); 
//you will get data in xml format & parse with SimpleXMLElement as Anthony has mentioned
?>

I also have worked with PHP5’s SOAP and found it very easier. Find the examples and tutorials at PHPycho’s link above and go for it.

Even for service development, it is far better as far as I know.