PHP SOAP 函数调用返回错误

发布于 2025-01-03 19:31:06 字数 3551 浏览 3 评论 0原文

在基本的 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}

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

Having trouble with a basic PHP/SOAP setup

I'm writing a SOAP client in PHP to talk to an existing SOAP Server. It also uses WS-Security.

I have successfully been able to connect (authenticated) and make a __getFunctions call, which returns an array of available functions using the following code:

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

?>

Which gives the following output (messy, but you get the idea):

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)
)

But when I try to call one of the listed functions directly (getVersion), by replacing

print_r($client->__getFunctions());

with

print_r($client->getVersion());

I get the following error

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}

I don't see any useful information in the error message, and the function I'm calling is one of the listed available options, and I believe my syntax is correct.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慵挽 2025-01-10 19:31:06

您可以尝试“手动”调用该函数吗?

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

这会产生什么结果?

Can you try 'manually' invoking the call to that function?

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

What does that yield?

厌倦 2025-01-10 19:31:06

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

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

如果异常为

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

You can try to init the SoapClient with the option:

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

If exception is

  • true, any error will raise an Exception.
  • false, you'll get a $client object containing a soapFault message.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文