user162810
user162810

Reputation:

PHP 5 SOAP client returns NULL when WSDL-provided function is called

I am trying to use a webservice to look for specific users from my PHP application. I have used that exact same webservice in ASP.NET with success.

Basically, I do everything like the PHP doc tells me to, and I use the same methods/variables I used in ASP.NET (for the webservice itself), but I can't seem to get a result.

The function is listed in __getFunctions() and should return anyType, which if I understand correctly is the equivalent of mixed in PHP:

array(1) { [0]=>  string(63) "anyType basicSearch(string $sharedSecret, string $searchParams)" } 

When I do call basicSearch() though, it seems returns NULL.

basicSearch() is supposed to return an XML document with the information. In ASP.NET I used to simply cast the response to, I believe, and XmlDocument. Should I do that in PHP too? With which representation of an XML document (SimpleXML, DOM, etc.)?

Could it show as NULL just because PHP can't understand the format?

Am I doing something wrong in PHP? Or should I look into the webservice itself and try to debug on that side?

<?php
    $client = new SoapClient($wsdl_url);

    echo $client->__getFunctions();
    echo "<br />\n";
    echo $client->basicSearch($key, $req);
?>

PS: I am using the PHP 5 library. Maybe using some other library like nu-soap would help? There seems to be more doc online about it.


Update:

Using an array to pass the parameter does not work, SOAP expects separate arguments. Calling __getLastRequest() returns a string concatenating $key and $req with no other XML. Calling __getLastResponse() returns an empty string. No exception is thrown whatsoever. It seems PHP does not know what to do with the arguments I give it, even though it has parsed the WSDL file since I get the function I use listed when I call __getFunctions().

Any help would be appreciated.

Update': Still no solution working. I am baffled...

Upvotes: 6

Views: 16685

Answers (2)

Josh
Josh

Reputation: 12722

I found this whole thing pretty confusing when I started using the SoapClient libraries in php. The proper way to format this stuff is as follows:

$client = new SoapClient( $wsdl_url, array( "trace" => 1 ) );

$params = array(
    "sharedSecret" => "thisIsSomeSecret",
    "searchParams" => "thisIsSomeSearchParam"
);

$response = $client->basicSearch( $params );

Without seeing the response, I can't tell you how to reference the return parameters, but the way its stored is as a member var of a stdClass object. Such that you reference the returns like this...

$reponse->paramName;

A nice trick if you keep the array( "trace" => 1 ) set of options in there is that you can call these two functions....

$respXML = $client->__getLastResponse();
$requXML = $client->__getLastRequest();

... to see the actual xml that gets sent out, to see if its well-formed. Careful, SoapClient is pretty buggy. Much better than nusoap though, don't go for that trash.

Upvotes: 5

Stepan Suvorov
Stepan Suvorov

Reputation: 26176

yeap

$client = new SoapClient( $wsdl_url, array( "trace" => 1 ) );

"trace" parameter helps

Upvotes: 1

Related Questions