PHP SOAP函数调用返回错误

时间:2012-02-08 13:24:18

标签: php soap ws-security

基本的PHP / SOAP设置有问题

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

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

<?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); 
}

?>

这给出了以下输出(凌乱,但你明白了):

Conn:YES
Array (
    [0] => editChannelResponse editChannel(editChannel $parameters)
    [1] => getDownloadTokenResponse getDownloadToken(getDownloadToken $parameters)
    [2] => startCallResponse startCall(startCall $parameters)
    [3] => getCallsResponse getCalls(getCalls $parameters)
    [4] => endCalendarCallResponse endCalendarCall(endCalendarCall $parameters)
    [5] => createChannelResponse createChannel(createChannel $parameters)
    [6] => getArchivesByCallIdsResponse getArchivesByCallIds(getArchivesByCallIds $parameters)
    [7] => getChannelsResponse getChannels(getChannels $parameters)
    [8] => createVRRResponse createVRR(createVRR $parameters)
    [9] => getTemplateResponse getTemplate(getTemplate $parameters)
    [10] => getTemplatesResponse getTemplates(getTemplates $parameters)
    [11] => getCallsByStatusResponse getCallsByStatus(getCallsByStatus $parameters)
    [12] => getCallResponse getCall(getCall $parameters)
    [13] => startCalendarCallResponse startCalendarCall(startCalendarCall $parameters)
    [14] => deleteChannelResponse deleteChannel(deleteChannel $parameters)
    [15] => editVRRResponse editVRR(editVRR $parameters)
    [16] => deleteVRRResponse deleteVRR(deleteVRR $parameters)
    [17] => getLiveStreamingsResponse getLiveStreamings(getLiveStreamings $parameters)
    [18] => getHashedPasswordResponse getHashedPassword(getHashedPassword $parameters)
    [19] => getVersionResponse getVersion(getVersion $parameters)
    [20] => endCallResponse endCall(endCall $parameters)
    [21] => getVRRsResponse getVRRs(getVRRs $parameters)
    [22] => getNumberOfArchivesResponse getNumberOfArchives(getNumberOfArchives $parameters)
    [23] => getArchivesResponse getArchives(getArchives $parameters)
    [24] => getVRRResponse getVRR(getVRR $parameters)
)

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

print_r($client->__getFunctions());

print_r($client->getVersion());

我收到以下错误

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}

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

2 个答案:

答案 0 :(得分:1)

您可以尝试'手动'调用该函数的调用吗?

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

收益是什么?

答案 1 :(得分:0)

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

$client = new SoapClient($wsdlPath, array("trace" => true, "exceptions" => true));

如果异常

  • true,任何错误都会引发Exception
  • false,您将获得一个包含$client消息的soapFault对象。