Jump to content



Photo
php c# wcf soap

  • Please log in to reply
3 replies to this topic

#1 sathenzar

sathenzar

    Neowinian

  • Joined: 12-June 06

Posted 14 October 2012 - 21:15

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?


#2 ZakO

ZakO

    Neowinian

  • Tech Issues Solved: 2
  • Joined: 21-September 07
  • Location: Finland

Posted 14 October 2012 - 21:26

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

echo $retval->GetDateTimeResult

GetDateTimeResult is a string, not an object.

#3 OP sathenzar

sathenzar

    Neowinian

  • Joined: 12-June 06

Posted 14 October 2012 - 21:35

weird, when I tried that it didn't work. Let me get the results from that though.

#4 OP sathenzar

sathenzar

    Neowinian

  • Joined: 12-June 06

Posted 14 October 2012 - 21:47

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.