Page 1 of 1

nuSOAP / .NET Web service

Posted: Wed Jun 24, 2009 8:54 pm
by chuckjones
Hi -

I'm having issues trying to setup a nuSOAP client that will connect to a .NET web service.

I can connect fine, the issue I have is with handling the resulting XML / array, what ever it is that's coming out. Here's the code:

Code: Select all

<?php
/*
 *  $Id: wsdlclient1.php,v 1.3 2007/11/06 14:48:48 snichol Exp $
 *
 *  WSDL client sample.
 *
 *  Service: WSDL
 *  Payload: document/literal
 *  Transport: http
 *  Authentication: none
 */
 
require_once ('lib/nusoap.php');
 
$wsdl = "http://dev.XXX.XXX/XXX.asmx?wsdl";
$params = array('XXX' => '204');
$namespace = "http://www.w3.org/2001/XMLSchema";
$soapAction = "http://tempuri.org/GetCityList";
 
$client = new nusoap_client($wsdl);
$result = $client->call('GetCityList', $params, $namespace, $soapAction);
 
 
//echo("<pre>". $client->response. "</pre>");
//echo $result["GetCityListResult"];
 
?>
 
You can see what combo's I've played with in the commented out echos. The GetCityListResult will yield an "array" but I have no idea how to iterate through it to get the fields that I need?

Thanks for your help,
Rob

Re: nuSOAP / .NET Web service

Posted: Thu Jun 25, 2009 2:24 am
by raine
Hi!

Try:

Code: Select all

 
 
$cityresult = $client->response["GetCityListResult"];
 
foreach ($cityresult as $cityitem)
{
echo $cityitem;
}
 
 

Re: nuSOAP / .NET Web service

Posted: Thu Jun 25, 2009 9:18 am
by chuckjones
Warning: Invalid argument supplied for foreach()

Code: Select all

 
 
$cityresult = $client->response["GetCityListResult"];
 
//print_r ($cityresult);
 
 foreach ($cityresult as $cityitem)
 {
 echo $cityitem;
 }
 
 
When I use the print_r -> I get the letter "H" alone.

Here's the output of $result:

Code: Select all

 
 
Array
(
    [schema] => Array
        (
            [element] => Array
                (
                    [complexType] => Array
                        (
                            [choice] => Array
                                (
                                    [element] => Array
                                        (
                                            [complexType] => Array
                                                (
                                                    [sequence] => Array
                                                        (
                                                            [element] => Array
                                                                (
                                                                    [0] => Array
                                                                        (
                                                                            [!name] => CityID
                                                                            [!minOccurs] => 0
                                                                        )
 
                                                                    [1] => Array
                                                                        (
                                                                            [!name] => StateCity
                                                                            [!minOccurs] => 0
                                                                        )
 
                                                                )
 
                                                        )
 
                                                )
 
                                            [!name] => Table
                                        )
 
                                    [!minOccurs] => 0
                                    [!maxOccurs] => unbounded
                                )
 
                        )
 
                    [!name] => NewDataSet
                    [!msdata:IsDataSet] => true
                    [!msdata:MainDataTable] => Table
                    [!msdata:Locale] => 
                )
 
            [!id] => NewDataSet
        )
 
    [diffgram] => Array
        (
            [NewDataSet] => Array
                (
                    [Table] => Array
                        (
                            [0] => Array
                                (
                                    [CityID] => 344
                                    [StateCity] => AK - Anchorage
                                    [!diffgr:id] => Table1
                                    [!msdata:rowOrder] => 0
                                )
 
                            [1] => Array
                                (
                                    [CityID] => 346
                                    [StateCity] => AK - Fairbanks
                                    [!diffgr:id] => Table2
                                    [!msdata:rowOrder] => 1
                                )
 
                            [2] => Array
                                (
                                    [CityID] => 347
                                    [StateCity] => AK - Juneau
                                    [!diffgr:id] => Table3
                                    [!msdata:rowOrder] => 2
                                )
 
                            [3] => Array
                                (
                                    [CityID] => 331
                                    [StateCity] => AL - Anniston
                                    [!diffgr:id] => Table4
                                    [!msdata:rowOrder] => 3
                                )
 
                            [4] => Array
                                (
                                    [CityID] => 332
                                    [StateCity] => AL - Tuscaloosa
                                    [!diffgr:id] => Table5
                                    [!msdata:rowOrder] => 4
                                )
 

Re: nuSOAP / .NET Web service

Posted: Thu Jun 25, 2009 1:49 pm
by chuckjones
Anyone ? Please, stuck bad here.

Re: nuSOAP / .NET Web service

Posted: Thu Jun 25, 2009 2:00 pm
by chuckjones
Damn it.

here's what perplexes me about this.

Using:

Code: Select all

 
echo ($result);
 
get "Array" as the output.

Go with this:

Code: Select all

 
for($i = 0; $i < count($result); $i++) {
    echo $result[$i];
}
 
and get

Notice: Undefined offset: 0
Notice: Undefined offset: 1 in ...

Re: nuSOAP / .NET Web service

Posted: Thu Jun 25, 2009 3:22 pm
by chuckjones
SOLVED:

$cityIDs=array();
$StateCities=array();
foreach($result['diffgram']['NewDataSet']['Table'] as $array){
$cityIDs[]=$array['CityID'];
$StateCities[]=$array['StateCity'];
}

foreach ($cityIDs As $cityID) {
echo($cityID). "<br>";
}