• 0

[PHP] Trying to get a simple string to return from a WCF method...nightmare


Question

So I thought hey, I program C# and WCF all of the time. Lets try to have some fun with calling a WCF method with a PHP client. What a freaking nightmare this has been 2 hours later of searching google to find out WHY is it so hard to return a simple string (it wants to stick it in a stdClass object). I can get it to return the method call with the right data (just a get date/time function), however I can not for the life of me directly access the date time string returned. Here's my php code:


<?php
 $client = new SoapClient("http://localhost:8731/TestService?wsdl");
 $params = array('param1'=>'test user'); // these parameters don't mean anything php just forces you to give it parameters for some awful reason.
 $retval = $client->__soapCall("GetDateTime", $params);
 var_dump($retval);

 echo $retval->GetDateTimeResult->string;
 for($i=0;$i<count($retval->string);$i++)
 {
  echo $retval->string[$i]->GetDateTimeResult->string;
 }
?>

I've tried so many different variations. But this is always the result:

object(stdClass)#2 (1) { ["GetDateTimeResult"]=> string(32) "Date Time: 10/14/2012 5:10:13 PM" } // <--------- obviously the call is working b/c here is the right info.

Notice: Trying to get property of non-object in C:\xampp\htdocs\domains\testapp\test.php on line 7

Notice: Undefined property: stdClass::$string in C:\xampp\htdocs\domains\testapp\test.php on line 8

I just want to access the simple string. What do I have to do to do that?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

If that's the full var_dump of $retval you should just be able to get it via

echo $retval->GetDateTimeResult[/CODE]

GetDateTimeResult is a string, not an object.

Link to comment
Share on other sites

  • 0

Ahhhh, I see the error. It was the next line causing the issue. I commented those lines out and I got what I needed. Thanks for offering that though I'm glad I retried it to see what I was doing wrong the first time.

Link to comment
Share on other sites

This topic is now closed to further replies.