Search code examples
phpsoapwsdlsoap-client

PHP SoapClient - Empty values returned by SOAP function calls


I'm trying to learn how SOAP works and trying to do some practice with the SoapClient built-in PHP class using a "Calculator" SOAP Web Service that I've found (http://www.dneonline.com/calculator.asmx?WSDL).

The problem is that I've tried to do some function calls to that web service, but everytime I do so it returns empty values.

This is the PHP code that I've made:

<?php
// SOAP practice file

ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl', 900);
ini_set('default_socket_timeout', 15);

$client = new SoapClient('http://www.dneonline.com/calculator.asmx?WSDL', array('trace' => 1));
print_r($client->__getFunctions());

try {
    $params = array('intA' => 3, 'intB' => 20);
} catch (SoapFault $fault){
    $fault->getMessage();
}

$objResult = $client->Add($parmas);
$result = $objResult->AddResult;

var_dump($result);
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";

And this is the verbose output that I have:

Array
(
    [0] => AddResponse Add(Add $parameters)
    [1] => SubtractResponse Subtract(Subtract $parameters)
    [2] => MultiplyResponse Multiply(Multiply $parameters)
    [3] => DivideResponse Divide(Divide $parameters)
    [4] => AddResponse Add(Add $parameters)
    [5] => SubtractResponse Subtract(Subtract $parameters)
    [6] => MultiplyResponse Multiply(Multiply $parameters)
    [7] => DivideResponse Divide(Divide $parameters)
)
int(0)
REQUEST:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:Add/></SOAP-ENV:Body></SOAP-ENV:Envelope>

Can you please help me telling me what's wrong with my code?
Thanks for helping!


Solution

  • You're using the wrong variable when calling the soap action.

     $objResult = $client->Add($parmas);
    

    it should be $params. Please turn on your error log next time you set out to code.