Jump to content

nuSOAP / .net web service


chuckjones

Recommended Posts

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:

 

<?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

Link to comment
https://forums.phpfreaks.com/topic/163578-nusoap-net-web-service/
Share on other sites

try

 

print_r($result);

 

I don't use nuSoap but PHP's Soap extension which looks similar

 

<?php
$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "REsponse:\n" . $client->__getLastResponse() . "\n";
?> 

 

If you want to see xml with response probably you should set trace to ON like in upper example.

 

TIP: look at the source.

Maybe $client->response is echoed, but you cant see it in browser because is xml document embedded in HTML.

Good start, a step closer.

 

print_r ($result);

 

Gave the following results.

 

Now with that output, trying to get that array with the elements in it.  Right where "[0] => Array" starts, that's the output that I'm looking to iterate through. 

 

Tried

 

print_r ($result['table']);

print_r ($result['NewDataSet']);

print_r ($result[1]);

 

All give me "Notice: Undefined index: NewDataSet"

 

Thanks for the help, ideas?

 

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][tr][td] => 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
                                )

 

Damn it.

 

here's what perplexes me about this.

 

Using: 

echo ($result);

 

get "Array" as the output.

 

Go with this:

 

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

 

and get 

 

Notice: Undefined offset: 0

Notice: Undefined offset: 1 in ...

 

 

foreach($result as $key=>$value) {
    echo $key.'  =  '.$value;
}

 

Output:

 

schema  =  Array

diffgram  =  Array

 

print_r($result[diffgram][NewDataSet]);

 

Output:

 

Use of undefined constant diffgram - assumed 'diffgram' in 

Notice: Use of undefined constant NewDataSet - assumed 'NewDataSet' in 


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] => 20
                    [stateCity] => AL - Birmingham
                    [!diffgr:id] => Table5
                    [!msdata:rowOrder] => 4
                )

Thanks!

Holy S!

 

Well, I'm a step away from sleeping now after days of pain.  Believe me there were 400 versions of my code.  Just broke down the simplest form for you.

 

Here's what comes out of it.  95% there.  Now how do I get the CityID and the StateCity values out in an iterative loop... so I can populate dropdowns, etc.

 

Thanks again.

 

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] => 20
                    [stateCity] => AL - Birmingham
                    [!diffgr:id] => Table5
                    [!msdata:rowOrder] => 4
                )

            [5] => Array
                (
                    [CityID] => 86
                    [stateCity] => AL - Decatur
                    [!diffgr:id] => Table6
                    [!msdata:rowOrder] => 5
                )

OK this is not tested, but I believe my logic to be correct. Not sure what way you want to go now, but now in the two new arrays each key will match as a pair for you to use as you need.

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

This worked!  Really thrilled, thank you much.  HOLY S what a chore this became for something that is pretty straight forward.  Will try to integrate all of my code today and then see if I have more hiccups.

 

What you did for me today is beyond appreciated! 

 

Used to .NET where we'd get a data table... handling things as an array is different for me....

 

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

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

Hey -

 

One question.

 

The Array names keep changing as they come out.... see below:

 

The "_x0037_6" was "_x0037_4" from the web service this AM?

 

foreach($result['diffgram']['NewDataSet']['_x0037_6'] as $array) {
   $TopVotes[]=$array['Votes'];
}

 

 

Is there a way to reference this non-explicitly?

 

Tried

 

$result['diffgram']['NewDataSet'][0] 

 

That didn't work.

 

Thanks

To help me understand can you post the results for this, then we will go from there. I think possibly this could be binary or an actually memory location, which may mean this is being passed by reference.

 
<?php
foreach($result['diffgram']['NewDataSet'] as $array) {
   print_r($array);
}
?>

Array
(
    [0] => Array
        (
            [Votes] => 11
            [CityState] => Chico, CA
            [Rank] => 1
            [!diffgr:id] => 861
            [!msdata:rowOrder] => 0
            [!diffgr:hasChanges] => modified
        )

    [1] => Array
        (
            [Votes] => 5
            [CityState] => Anchorage, AK
            [Rank] => 2
            [!diffgr:id] => 862
            [!msdata:rowOrder] => 1
            [!diffgr:hasChanges] => modified
        )

    [2] => Array
        (
            [Votes] => 5
            [CityState] => Los Angeles, CA
            [Rank] => 3
            [!diffgr:id] => 863
            [!msdata:rowOrder] => 2
            [!diffgr:hasChanges] => modified
        )

)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.