问题描述
我正在尝试编写一个PHP脚本,该脚本将连接到SightMax接口的SOAP客户端.使用下面的代码,我可以打印出可用功能的列表,但是,当我尝试调用任何功能时,都会出现以下错误.
I'm attempting to write a PHP script that will connect to the SOAP client for our SightMax interface. With the code below I am able to print out a list of functions available however when I try and call any function I am getting the the following error.
<?php
$client = new SoapClient('http://domain.com/SightMaxWebServices/SightMaxWebService.svc?wsdl', array('soap_version' => SOAP_1_2));
var_dump($client->__getFunctions());
$result = $client->__call("GetSiteSummary", array());
echo "<pre>";
print_r($result);
echo "</pre>";
?>
Fatal error: Uncaught SoapFault exception: [s:Sender] The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'SmartMax.SightMax.Agent.Operator/IRemotedWebsiteAdministrator/GetSiteSummary'. in test2.php:7 Stack trace: #0 test2.php(7): SoapClient->__call('GetSiteSummary', Array) #1 {main} thrown in test2.php on line 7
最近几天,我一直在研究此错误,并且阅读了许多说明可能存在问题的文章.据我了解,发生此错误是因为为wsHttpBinding配置了SOAP客户端,并且PHP的SOAP客户端内置不支持wsHttpBinding或我需要专门指定SOAP操作.
I've been researching this error for the last couple days and I've read different articles stating possible issues. From what I understand this error occurs because the SOAP client is configured for wsHttpBinding and either the build in SOAP client for PHP does not support the wsHttpBinding or I need to specifically specify the SOAP action.
有人能为我阐明这一点吗?当我精通PHP时,请记住,使用SOAP是我的新手,所以逐步操作非常有帮助.
Can anyone shed any light on this for me? Please keep in mind while I'm versed with PHP working with SOAP is new to me so step by steps are very helpful.
预先感谢.
推荐答案
WCF似乎正在SOAP信封中寻找操作.您可以通过以下方式将其添加到使用PHP的SoapClient的调用中:
WCF seems to be looking for the action in the SOAP envelope. You can add it to your call with PHP's SoapClient this way:
$actionHeader = new SoapHeader('http://www.w3.org/2005/08/addressing',
'Action',
'http://soapaction.that.was.in.the.wsdl');
$client->__setSoapHeaders($actionHeader);
如果更改第三个参数,并在$ client实例化和__call()之间添加该参数,它应该清除错误(并且可能带来新的错误,SOAP不好玩吗?)
If you change the third parameter and add that between your instantiation of $client and the __call() it should clear the error (and possibly bring on new ones, isn't SOAP fun?)
仅供参考,在经历了相同的问题后,我发现__getLastRequestHeaders(),__getLastRequest(),__getLastResponseHeaders()和__getLastResponse()函数非常方便,以查看我尝试的内容是否有任何效果(请注意,需要在您的SoapClient选项中添加"trace" =>"1"才能使它们起作用.)
Also FYI, having just gone through this same problem, I found the __getLastRequestHeaders(), __getLastRequest(), __getLastResponseHeaders(), and __getLastResponse() functions very handy to see if what I was trying had any effect (note that you need to add "trace" => "1" to your SoapClient options for those to work.)
这篇关于PHP致命错误:“在消息''上指定的SOAP操作与HTTP SOAP操作不匹配".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!