Jump to content

Soap Web Service In Php


skaterdav85
 Share

Recommended Posts

so im trying to consume this SOAP web service, and it's returning "stdClass Object ( )". What does that mean?This is my php code

<?php$params->ID = "27";$ppl = "http://dbf065:8080/MapKeywordRecommender?wsdl";$pplRequest = new SoapClient($ppl);$result = $pplRequest->getRecommendedKeywords($params);print_r($result);?>

Link to comment
Share on other sites

im basically translating this web service consumption from someone who did it in java. In Java terms, they said that I should get back an array of KeywordScore objects, which are just javabeans. Do you know what that means? Im not too familiar with SOAP services in php =/.

Link to comment
Share on other sites

Java people like to use their own terminology, I'm not sure what that means. A "javabean" doesn't mean anything to me. I don't think you're setting the params correctly, I don't think you're able to do this:$params->ID = "27";without setting $params to an instance of an object first.

Link to comment
Share on other sites

well i tried changing it to:$params = "27", and it returned the same thing.This is the java code:

public interface MapKeywordRecommenderService extends Remote{	public KeywordScore[] getRecommendedKeywords(String ID) throws RemoteException;}

Looking at this, it looks like I can just pass the "getRecommendedKeywords" method a string. But im not sure why when I print the result, i get that same "stdClass Object ( )".

Link to comment
Share on other sites

public KeywordScore[] getRecommendedKeywords(String ID) throws RemoteException;That says that it returns an array of KeywordScore objects.

But im not sure why when I print the result, i get that same "stdClass Object ( )".
If you're using PHP < 5, PHP won't print properties for objects using print_r. You can also try var_dump and see if that prints anything different. As for why the method returns what it does I can't really say.
Link to comment
Share on other sites

AFAIK, if a web service returns an array, PHP creates an stdClass object that should be accessible as an array (via the ArrayAccess interface). In addition to that, as your code shows, the function returns KeywordScore objects. Depending on the way the web service is created, you may have to go deeper into the hierarchy... or not.Try it like that

<?php$params = "27";$ppl = "http://dbf065:8080/MapKeywordRecommender?wsdl";$pplRequest = new SoapClient($ppl);$result = $pplRequest->getRecommendedKeywords($params)[0];print_r($result);?>

and see if that gives out any errors (you have display_errors enabled and error_reporting set to E_ALL & E_STRICT, right?).

Link to comment
Share on other sites

and see if that gives out any errors (you have display_errors enabled and error_reporting set to E_ALL & E_STRICT, right?).
display_errors is enabled, and error_reporting says 6135 for the local value and master value (not sure what that means). I tried this:
<?php$params = "27852";$ppl = "http://dbf065:8080/MapKeywordRecommender?wsdl";$pplRequest = new SoapClient($ppl);//$result = $pplRequest->getRecommendedKeywords($params);$result = $pplRequest->getRecommendedKeywords($params[0]);print_r($result);var_dump($result);?>

and my error was still the same:stdClass Object ( ) object(stdClass)#2 (0) { }Any other ideas? Could the web service not be working or turned off?

Link to comment
Share on other sites

The later code you tried has a whole other meaning that isn't far from your original one.

$params[0]

means in this case (because $params is a string) the first character in the string.I think I made a mistake in forgetting how PHP deals with returned arrays in general. Try it like this:

$resultArr = $pplRequest->getRecommendedKeywords($params);$result = $resultArr[0];

Edited by boen_robot
Link to comment
Share on other sites

that returned a fatal error:Fatal error: Cannot use object of type stdClass as array in C:\xampp\htdocs\Aeropops.php on line 13well it looks like im being returned an object, right? I think it has to do with the hierarchy. Is there anyway I can see what that looks like?? This is a pain because whats coming to the screen isnt very helpful.

Link to comment
Share on other sites

The object doesn't have any properties, it's an empty object. If you run this:

<?phpclass testclass{  private $priv;  public $pub;    function __construct()  {	$this->priv = 'private var';	$this->pub = 'public var';  }}$obj = new testclass();print_r($obj);$json = '{"prop1": "val1", "prop2": "val2"}';$obj2 = json_decode($json);print_r($obj2);$json = '{}';$obj3 = json_decode($json);print_r($obj3);?>

it will print this:

testclass Object(	[priv:private] => private var	[pub] => public var)stdClass Object(	[prop1] => val1	[prop2] => val2)stdClass Object()

When it prints this:stdClass Object ( )That's an object with no properties. You'll probably need to check the Java code for the web service to see what it's actually doing, the function prototype says it should be returning an array.

Link to comment
Share on other sites

Maybe I am reading the WSDL file incorrectly. Looking at the WSDL file, the message input and output are not like the ones in the tutorial where its like:

<part name="value" type="xs:string"/>

Instead, there is no type and the part looks like this:

<part name="parameters" element="tns:getRecommendedKeywords" />

How do i interpret this?

Link to comment
Share on other sites

Ok well I got it working. It turns out, the following input parameter stated in the message part was an associative array:

<part name="parameters" element="tns:getRecommendedKeywords" />

getRecommendedKeywords was an associative array. I had to look at the targetNamespace in the root element <definitions> tag to figure this out. wierd....

Link to comment
Share on other sites

The results of a print_r come back like this:

stdClass Object ( [return] => Array ( [0] => stdClass Object ( [keyword] => networks [score] => 1 [source] => ieee ) [1] => stdClass Object ( [keyword] => distributed computing [score] => 1 [source] => ieee ) [2] => stdClass Object ( [keyword] => information [score] => 0.5 [source] => acm ) [3] ... (more)

can someone help me interpret what this means? Am I getting back an object arrays? How do i access a value?

Link to comment
Share on other sites

It will be easier to use View->Source to look at the output from print_r, or print it in between <pre> tags or something. PHP indents everything but the browser ignore the whitespace when it displays it.That's an object, not an array. The only property I see listed is the return property ($obj->return), which looks like an array of other objects. Each object in the return array has keyword, score, and source properties.

Link to comment
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
 Share

×
×
  • Create New...