返回错误的PHP SOAP函数调用

返回错误的PHP SOAP函数调用,php,soap,ws-security,Php,Soap,Ws Security,基本PHP/SOAP设置有问题 我正在用PHP编写一个SOAP客户机来与现有的SOAP服务器通信。它还使用WS-Security 我已成功连接(通过身份验证)并进行调用,使用以下代码返回可用函数数组: <?php $wsdlPath = "https://xxx.xxx.xxx.xxx/services/Service?wsdl"; $ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-sec

基本PHP/SOAP设置有问题

我正在用PHP编写一个SOAP客户机来与现有的SOAP服务器通信。它还使用WS-Security

我已成功连接(通过身份验证)并进行调用,使用以下代码返回可用函数数组:

<?php

$wsdlPath = "https://xxx.xxx.xxx.xxx/services/Service?wsdl";

$ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
$token = new stdClass;
$token->Username = new SOAPVar('xUSERx', XSD_STRING, null, null, null, $ns);
$token->Password = new SOAPVar('xPASSx', XSD_STRING, null, null, null, $ns);

$wsec = new stdClass;
$wsec->UsernameToken = new SoapVar($token, SOAP_ENC_OBJECT, null, null, null, $ns);

$headers = new SOAPHeader($ns, 'Security', $wsec, true);

if (!$client)
{
    $client = new SoapClient($wsdlPath);
    echo "Conn:YES";
}
else
{
    echo "Conn:NO";
}

$client->__setSOAPHeaders($headers);

try
{
   print_r($client->__getFunctions());    
}
catch (SoapFault $exception)
{
   print($exception); 
}

?>
但是当我试图直接调用其中一个列出的函数(getVersion)时,通过替换

print_r($client->__getFunctions());

我得到以下错误

Conn:YES
SoapFault exception: [soap:Server] 
Fault occurred while processing. in /var/data/www/xxx/beta/soap.php:29 
Stack trace: #0 [internal function]: SoapClient->__call('getVersion', Array) #1 
/var/data/www/xxx/beta/soap.php(29): SoapClient->getVersion() #2 {main}

我在错误消息中没有看到任何有用的信息,我正在调用的函数是列出的可用选项之一,我相信我的语法是正确的。

您可以尝试使用以下选项初始化SoapClient:

$client = new SoapClient($wsdlPath, array("trace" => true, "exceptions" => true));
如果例外是

  • true
    ,任何错误都将引发
    异常
  • false
    ,您将得到一个包含
    soapFault
    消息的
    $client
    对象

能否尝试“手动”调用该函数的调用

$response = $client->__doRequest( $postdata, 'soaplistenerurl', 'getVersion', 1 );

这会产生什么结果?

soap.php的第29行是什么?第29行是我对print\r($client->getVersion())进行更改的关键行;还有更多关于堆栈跟踪的信息吗?不幸的是,我已经包含了我所有的信息。请尝试运行我发布的建议,我很好奇它的作用。我不确定这是否会有帮助,因为他在调用SOAP侦听器提供的“可用”函数时出错。添加该参数对输出没有影响。您是否尝试使用参数调用getVersion,即使是空参数?是,没有更改。根据API手册,这个特定函数不需要参数,但我已经尝试了使用paramaters,以防万一。我确信您确实这样做了,但您是否尝试调用getVersion以外的其他函数?如果getVersion在Soap服务器端出现故障怎么办?$postdata的值是多少?很抱歉,这是我第一次使用SOAP,所以对我来说这是一个陌生的领域。。所以
用于测试。不用担心,如果您以前没有使用过SOAP,它可能会成为一个怪物,尤其是如果您对web服务不熟悉,它似乎根本不会产生任何输出。您需要检查$response的内容,看看它是否成功
$client = new SoapClient($wsdlPath, array("trace" => true, "exceptions" => true));
$response = $client->__doRequest( $postdata, 'soaplistenerurl', 'getVersion', 1 );