I implemented a simple SOAP service in .NET.
I wrote a test client in .NET and it connects and works perfectly.
Now in my final solution I need PHP to connect to it. The manual has zero example code and does not explain what is returned from calling a SOAP method like a method of the client class. Some web pages seem to treat it like the return value of the service, some treat it like a PHP object (service or fault?)
I cannot get it to work no matter what I try. I've went through and mimicked several examples and each fails with exceptions or errors.
Here is my current PHP code:
Code: Select all
// WCF Test
try
{
$client = new SoapClient("http://localhost:8001?wsdl");
echo("<BR>Dumping client object:<BR>");
var_dump($client);
echo("<BR><BR>");
echo("Dumping client functions:<BR>");
var_dump($client->__getFunctions());
echo("<BR><BR>");
echo("Calling SOAP Add function with params 2 and 5<BR><BR>");
$result = $client->AddPlus(5,2);
if( is_soap_fault($result) == true )
{
echo "There was a fault.<BR><BR>";
}
else
{
echo("Got result: " . $result . "<BR><BR>");
}
//$userID = $records[0]->m_userID;
//$courseID = $records[0]->m_courseID;
//echo("Calling SOAP NACs function with params userID=" . $userID . " courseID=" . $courseID . "<BR><BR>");
//$client->UpdateNACs($userID, $courseID);
}
catch(Exception $e)
{
echo 'Caught exception: '. $e->getMessage(). "\n";
}
How do you call a wcf method from PHP?
P.S. are the site moderators aware that you cannot see what you are typing as this text area scrolls up with every keystroke?
EDIT: It looks like I actually got the call to go through with the following code, but I do not know how to get the result out of the returned value. I've treated it as an array and as an object and cannot get tyhe value without error:
Code: Select all
try
{
$client = new SoapClient("http://localhost:8001/?wsdl");
echo("<BR>Dumping client object:<BR>");
var_dump($client);
echo("<BR><BR>");
echo("Dumping client functions:<BR>");
var_dump($client->__getFunctions());
echo("<BR><BR>");
$parameters = array("addend1" => 5.0, "addend2" => 2.0);
echo("Calling SOAP Add function with params ");
var_dump($parameters);
echo ("<BR><BR>");
$result = $client->AddPlus($parameters);
if( is_soap_fault($result) == true )
{
echo "There was a fault.<BR><BR>";
}
else
{
echo("Got result: ");
var_dump($result);
echo("<BR><BR>");
//echo($result->AddPlusResult);
}
object(SoapClient)#2 (2) { ["_soap_version"]=> int(1) ["sdl"]=> resource(6) of type (Unknown) }
Dumping client functions:
array(2) { [0]=> string(44) "AddplusResponse Addplus(Addplus $parameters)" [1]=> string(53) "UpdateNACsResponse UpdateNACs(UpdateNACs $parameters)" }
Calling SOAP Add function with params array(2) { ["addend1"]=> float(5) ["addend2"]=> float(2) }
Got result: object(stdClass)#3 (1) { ["AddplusResult"]=> float(7) }