How to Read and use NuSoap Response Array into Variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neoblitz
    New Member
    • Mar 2008
    • 1

    How to Read and use NuSoap Response Array into Variables

    Hi Guys, I'm very new to NuSoap. I'm able to call a webservice which actually returned me results.. But I'm having trouble to read the response or I simply don't understand how to read the response.. here is the code i've used to call the service. It returns a kind of big array so i'm so much lost inside it.. I would be grateful if someone help me out on reading the array values into variables so that i can do something depends on the result values.. here is the sample codes..

    Calling the GetCustomerProf ile Webservice:
    [PHP]
    <?php
    //GetCustomerProf ile
    $wsdlURL = "http://www.worldcard.c om.my/MerchantV4/wcservices.asmx ?WSDL";
    require_once('n usoap.php');

    // set the URL or path to the WSDL document
    $wsdl = "http://www.worldcard.c om.my/MerchantV4/wcservices.asmx ?WSDL";

    // instantiate the SOAP client object
    $soap = new soapclient($wsd l,"wsdl");

    $soap->useHTTPPersist entConnection() ;

    $parameters['parameters']['AppID'] = "GWCBIZPORT AL";
    $parameters['parameters']['UserID'] = "NZN_WEB";
    $parameters['parameters']['Password'] = "ABC123";
    $parameters['parameters']['CustomerID'] = "0154677957 ";
    $result = $soap->call("GetCusto merProfile", $parameters);
    if($error = $soap->getError()){ die($error);}

    // Not sure about how to read the array results
    $collrecord = $result["GetCustomerPro fileResult"];

    // this part also not working
    foreach ($collrecord["OutputPara ms"] as $record){
    echo "<br>Name: ".$record["CustomerNa me"];
    echo "<br>Email: ".$record["EmailAddre ss"];
    }

    echo "<pre>" . print_r($result ) . "</pre>";
    ?>[/PHP]

    Now the Result returned as:
    Code:
    <br>Name: 1<br>Email: 1<br>Name: <br>Email: <br>Name: <br>Email: <br>Name: <br>Email: <br>Name: [<br>Email: [<br>Name: M<br>Email: M<br>Name: T<br>Email: T<br>Name: M<br>Email: M<br>Name: 0<br>Email: 0<br>Name: D<br>Email: D<br>Name: I<br>Email: I<br>Name: M<br>Email: M<br>Name: 0<br>Email: 0<br>Name: 0<br>Email: 0<br>Name: 0<br>Email: 0<br>Name: R<br>Email: R<br>Name: 0<br>Email: 0<br>Name: 0<br>Email: 0<br>Name: 0<br>Email: 0<br>Name: 0<br>Email: 0<br>Name: E<br>Email: E<br>Name: w<br>Email: w<br>Name: R<br>Email: R<br>Name: 0<br>Email: 0<br>Name: 2<br>Email: 2<br>Name: 0<br>Email: 0<br>Name: 0<br>Email: 0<br>Name: <br>Email: Array
    (
        [GetCustomerProfileResult] => Array
            (
                [OutputParams] => Array
                    (
                        [CustomerID] => 154677957
                        [PreferenceFlags] => Array
                            (
                                [PreferenceFlag] => Array
                                    (
                                        [0] => Array
                                            (
                                                [Name] => CB
                                                [Value] => DCX
                                            )
    
                                        [1] => Array
                                            (
                                                [Name] => EMA
                                                [Value] => Y
                                            )
    
                                        [2] => Array
                                            (
                                                [Name] => HP
                                                [Value] => 
                                            )
    
                                        [3] => Array
                                            (
                                                [Name] => LP
                                                [Value] => E
                                            )
    
                                        [4] => Array
                                            (
                                                [Name] => PIN
                                                [Value] => Y
                                            )
    
                                        [5] => Array
                                            (
                                                [Name] => SMS
                                                [Value] => Y
                                            )
    
                                    )
    
                            )
    
                        [Telephones] => Array
                            (
                                [Telephone] => Array
                                    (
                                        [TelDescription] => HOME
                                        [TelNumber] => 12345
                                        [BestNumberFlag] => 1
                                    )
    
                            )
    
                        [Addresses] => Array
                            (
                                [Address] => Array
                                    (
                                        [AddressDescription] => HOME
                                        [Address1] => aaa
                                        [Address2] => bbb
                                        [Address3] => ccc
                                        [City] => 
                                        [State] => 
                                        [Country] => MALAYSIA
                                        [PostCode] => 
                                        [CorrespondenceFlag] => 1
                                    )
    
                            )
    
                        [CustomerName] => [TESTING] WEIS IA2
                        [CustomerTitle] => MR
                        [CustomerTypeCode] => TEST
                        [Gender] => M
                        [BusinessEmployer] => 0
                        [ICPassportNo] => DCX-1001
                        [ICPassportType] => I
                        [ICPassportCountry] => MALAYSIA
                        [CompOverDraftLimit] => 0
                        [CustEntryDeposit] => 0
                        [RecordActualFlag] => 0
                        [NotesComments] => RWB PREPAID DINING CARD ONSITE ISSUANCE
                        [NotesCommentsBufferSize] => 0
                        [TelephoneStatus] => 0
                        [AddressStatus] => 0
                        [EmailStatus] => 0
                        [PreferredLanguage] => EN
                        [EmailAddress] => wsooi@genting.com.my
                        [CustomerCurrency] => RM
                        [PrincipalCustomerID] => 0
                        [DateOfBirth] => 28/12/1975
                        [ReturnCode] => 0
                        [ErrorCode] => 0
                        [ErrorDescription] => 
                    )
    
            )
    
    )
    <pre>1</pre>
    • I noticed the $result inside pre printed as 1.
    • Another Issue is it takes a load of time to call the webservice.


    Any help will be highly appreciated. Thanks in Advance
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Neo.

    In no particular order:

    [code=php]echo "<pre>" . print_r($result , true) . "</pre>";[/code]
    Note the second parameter to print_r().

    If it's taking a long time to get results from the webservice, it might just be because your server doesn't have good bandwidth, maybe the server hosting the webservice is running inefficient code... there's lots of possibilities that might just be out of your control.

    There are ways around this, depending on how your app is set up. For example, you can cache the result of 'GetCustomerPro file' until the User makes a change to his profile.

    Also, you might experiment with queueing up requests in the background. For example, if the User makes a change to his profile, you can run a PHP script in the background to contact the webservice and meanwhile let the User know that it might take a few minutes before his changes are saved.

    Anyway, on to your parsing problem. Save the best for last, right?

    Nothing about the code is immediately jumping out at me. Try print_r()'ing $collrecord and $record just to make sure you're working with what you think you're working with.

    Comment

    Working...