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="]Array[/FONT]
[FONT="]([/FONT]
[FONT="] [getAllClientsResult] => <NewDataSet>[/FONT]
[FONT="] <Table>[/FONT]
[FONT="] <name>Kenny</name>[/FONT]
[FONT="] <Surname>France</surname>[/FONT]
[FONT="] </Table>[/FONT]
[FONT="]<Table>[/FONT]
[FONT="] <name>Kenny2</name>[/FONT]
[FONT="] <Surname>France2</surname>[/FONT]
[FONT="] </Table>[/FONT]
[FONT="]<Table>[/FONT]
[FONT="] <name>Kenny3</name>[/FONT]
[FONT="] <Surname>France3</surname>[/FONT]
[FONT="] </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->__construct(Array) #1 {main} thrown in
K-
Give this a bash.
<?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("%s %s\\r\
", $user->name, $user->Surname);
}
?>
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…
The_Mog
January 20, 2010, 7:22am
10
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
PHPycho
January 20, 2010, 7:26am
11
The_Mog:
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
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("%s\\r\
", $user->debtorname);
}
?>
The_Mog
January 20, 2010, 7:46am
13
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?
PHPycho
January 20, 2010, 11:21am
14
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
?>
PHPycho:
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.