Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert stdClass to String in PHP using C# web service

So, I know this question has been asked a lot but I'm doing as much research as I can and I can't find an answer that's worked for me yet.

I have a C# web service for a project and as a demo I'm trying to do stuff like this:

[WebMethod]
public string GetResponse(string input)
{
    return "You entered " + input + ".";
}

And in PHP:

<?php
    $client = new SoapClient("http://localhost:49283/MyService.asmx?wsdl");
    $client->GetResponse("hello");
?>

Return value looks like this when you invoke it using the web service's home page (URL is http://localhost:49283/BookService.asmx/GetResponse?input=hello):

<string xmlns="http://tempuri.org/">You entered hello.</string>

Doing a var_dump of the response looks like this:

object(stdClass)#2 (1) { ["GetResponseResult"]=> string(13) "You entered ." }

So I know it has a string inside it, but I have no idea how to "extract" it out of the object. Can anyone help with this?

like image 607
djmordigal Avatar asked Mar 05 '26 03:03

djmordigal


1 Answers

You can access to the value with $result->GetResponseResult test this code:

<?php
    $client = new SoapClient("http://localhost:49283/MyService.asmx?wsdl");
    $result = $client->GetResponse("hello");
    echo $result->GetResponseResult;
?>
like image 86
Adrian Cid Almaguer Avatar answered Mar 07 '26 16:03

Adrian Cid Almaguer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!