PHP SOAP 函数调用返回错误
在基本的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试“手动”调用该函数吗?
这会产生什么结果?
Can you try 'manually' invoking the call to that function?
What does that yield?
您可以尝试使用以下选项初始化 SoapClient:
如果异常为
true
,则任何错误都会引发Exception
。false
,您将获得一个包含soapFault
消息的$client
对象。You can try to init the SoapClient with the option:
If exception is
true
, any error will raise anException
.false
, you'll get a$client
object containing asoapFault
message.