Since Web Service Description Language (WSDL) is to be used between language so that a PHP program can call a .NET web service or the other way around. So here we create a PHP Soap Client that will call the .Net Web service created from a previous post (Web Service).
As before with the soap client for a PHP server (PHP server previous post) we just need to link to the WSDL output of the .NET web service as below
$client = new SoapClient("http://localhost/csharp/web_service.asmx?wsdl")
so if you tried to call the function / web method.
The error would be
Catchable fatal error: Object of class stdClass could not be converted to string in
this does not mean that much or really point to where the problem is, the actual problem is not the passing parameters (even through they are in a complex format) but the return from the $client object, because .NET returns a array object as such, so if you
the output would be
stdClass Object ( [AddResult] => 0 )
thus to gain access to the actual result you would need to reference the first part of the returned array named AddResult
but the parameters being passed are not!!, so if you look at the WSDL file generated from the .NET web service it has
complex types and thus if you try to pass in parameters to the function Add (as the web service client does) as a normal PHP way it is not passing in the numeric values from the php code, the reason for this PHP has to specify the actual names of the passing parameters within a array.. as
print_r( $client->Add(array("a" => "5", "b" =>"2")));
which displays a better result for us..
stdClass Object ( [AddResult] => 7 )
So the best way to remember is that if you are calling a .NET WSDL web service, then always pass in a array with the WSDL function parameters within a index array and the return result is always function name + Result (AddResult)
echo $client->Add(array("a" => "5", "b" => "2"))->AddResult;
So here is the full code to pull back the code with some debugging information.
1, // enable trace to view what is happening "exceptions" => 0, // disable exceptions "cache_wsdl" => 0) // disable any caching on the wsdl, encase you alter the wsdl server ); // get a response from the WSDL zend server function getQuote for the day monday print_r( $client->Add(array("a" => "5", "b" =>"2"))); // display what was sent to the server (the request) echo "
Request :".htmlspecialchars($client->__getLastRequest()) .""; // display the response from the server echo "