PHP SoapClient-SOAP函数调用返回的空值

时间:2018-12-09 17:40:19

标签: php soap wsdl soap-client

我试图学习SOAP的工作方式,并尝试使用我发现的(http://www.dneonline.com/calculator.asmx?WSDL)的“计算器” SOAP Web服务对SoapClient内置PHP类进行一些练习。

问题是我试图对该Web服务进行一些函数调用,但是每次这样做都会返回空值。

这是我编写的PHP代码:

<?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";

这是我的详细输出:

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>

能帮我告诉我代码有什么问题吗?
感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您在调用soap操作时使用了错误的变量。

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

应为 $ params 。下次您设置代码时,请打开错误日志。