2

I am trying to call a function in my C# webservice but get this error:

"Catchable fatal error: Object of class stdClass could not be converted to string".

This is my code:

<?php 
try
{
    $soap_client = new
    soapclient("http://tsb01.cnap.hv.se/PersonalService/ServicePersonal.svc?wsdl");
    $quote = $soap_client->VisaPersonNamn();
    echo "$quote";        


}
catch(SoapFault $exception)
{
    echo $exception->getMessage();
}
?>

The webservice is really simple it only returns one string..

Can't figure out what's wrong.. help would be really nice!! :)

Federkun
  • 36,084
  • 8
  • 78
  • 90
Newbie1337
  • 199
  • 1
  • 12

2 Answers2

1

Change this line echo "$quote"; to echo $quote->VisaPersonNamnResult; if you will always have a single record in response.

If you receive multiple records, you can iterate over each record like,

foreach( $quote as $record )
{
    echo $record;
}

More details on accessing PHP Objects here

Community
  • 1
  • 1
viral
  • 3,724
  • 1
  • 18
  • 32
0

Firstly The problem is VisaPersonNamn returns an object, and you are terating it as an string by writing echo "$quote"; instead of it use either var_dump($quote) or print_r($quote).

Now as you show that var_dump($quote) gives you output like below:-

 object(stdClass)#2 (1) { ["VisaPersonNamnResult"]=> string(4) "Kurt" }

To show value Kurt,You need to call like this:-

echo $quote->VisaPersonNamnResult;
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98