我正在尝试使用SoapClient类从PHP连接到WCF服务。我可以使用WCFStorm成功连接和遍历API但是似乎无法正确构造头数据以便从SoapClient进行身份验证。有效的WCF请求如下:
<MyMethod>
<OutgoingHeaders attr0="MsgHeaderArray" isNull="false">
<MsgHeaderArray0>
<Name>ApiKey</Name>
<Namespace>http://www.service.com/namespace</Namespace>
<ItemType>System.String</ItemType>
<Value>ABC123</Value>
<Direction>Outgoing</Direction>
</MsgHeaderArray0>
</OutgoingHeaders>
<MethodParameters>
<colour>Red</colour>
<size>Large</size>
</MethodParameters>
</MyMethod>
我用来连接api并调用方法的代码是:
$params = array(
'colour' => 'Red',
'size' => 'Large'
);
$service = new SoapClient('http://www.service.com/service.svc?wsdl');
$header = new SoapHeader('http://www.service.com/namespace', 'ApiKey', 'ABC123', FALSE);
$service->__setSoapHeaders(array($header));
$service->MyMethod($params);
但是我收到拒绝访问错误,我猜是因为SoapHeader格式不正确?
SoapFault: Access is denied. in SoapClient->__call()
感谢您提供任何帮助。