4 posts in this topic

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:

 $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);

 echo $retval->GetDateTimeResult->string;
  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?

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.