3

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?

3
  • try $obj->GetResponseResult Commented Apr 18, 2015 at 3:04
  • Yes! That works. However, the only problem left is that it doesn't echo the input. I simply get "You entered ." Do you know what's causing that to happen? Commented Apr 18, 2015 at 3:12
  • try $client->GetResponse( array('input' => "hello" ) ); Commented Apr 18, 2015 at 3:22

2 Answers 2

1

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;
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes! That works. However, the only problem left is that it doesn't echo the input. I simply get "You entered ." Do you know what's causing that to happen?
0

Use $obj->GetResponseResult to get result from object(stdClass)#2 (1) { ["GetResponseResult"]=> string(13) "You entered ." }

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.