3
votes

I'm making what's likely to be a really simple mistake but can't seem to work out. I'm attempting to send a SOAP request to a web service using the PHP SoapClient library. The following error occurs when attempting to print:

"Object of class stdClass could not be converted to string"

Here is the code, taken primarily from the PHP SoapClient Manual.

<?php

try { 
    $options = array( 
                     'soap_version'=>SOAP_1_2, 
                     'exceptions'=>true, 
                     'trace'=>1, 
                     'cache_wsdl'=>WSDL_CACHE_NONE 
                    ); 
    $client = new SoapClient('http://www.webservicex.net/ConvertTemperature.asmx?WSDL', $options); 

    $results = $client->ConvertTemp(array('Temperature'=>'100', 'FromUnit' => 'degreeCelsius',
                                          'ToUnit' => 'degreeFahrenheit')); 
    } 
    catch (Exception $e) 
    { 
      echo "<h2>Exception Error!</h2>"; 
      echo $e->getMessage(); 
    } 

$results = $client->ConvertTemp(array('Temperature'=>'100', 'FromUnit' => 'degreeCelsius',
                                    'ToUnit' => 'degreeFahrenheit')); 

print $results;
?>

I understand that the message is telling me that I'm trying to print an entire object rather than a member of that object. What I don't understand is that I'm expecting a call to ConvertTemp to return a string. Why is an object being return? Thanks in advance for any help.

1

1 Answers

2
votes

Well, your expectations may be wrong. A var_dump or print_r can shed light on what $results actually is, re-examing the wsdl could tell you why:

Hint: __getTypes():

struct ConvertTempResponse {
 double ConvertTempResult;
}