php和soap标头令牌身份验证

时间:2015-10-09 07:34:16

标签: php soap soapheader

我需要这个xml:

<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns1="https://server/">
<soapenv:Header>
<authenticate>111111111111</authenticate>
<SOAP-ENV:Header/>

我的PHP代码是:

$head = new stdClass();
$head->authenticate='1111111111111111';
$header = new SoapHeader('ns1','authenticate',$head,false);
$client = new SoapClient ('https://server',array("trace" => 1, "exceptions" => 1));
$client->__setSoapHeaders($header);

我得到这个XML:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns1="https://server" 
xmlns:ns2="https://server">
<SOAP-ENV:Header>
<ns2:authenticate>
<authenticate><BOGUS>anc401t9n4dknmgp2bv629ori7</BOGUS>
</authenticate></ns2:authenticate>
</SOAP-ENV:Header
><SOAP-ENV:Body>...

我如何获得所需的xml?可以用php客户端SoapClient完全重写soapheader吗?或者我如何在不创建新命名空间的情况下添加一个字符串?

1 个答案:

答案 0 :(得分:0)

如果您的Web服务在其WSDL中有详细记录,请尝试使用wsdltophp.comPackageGenerator,因为它会生成方法以便非常轻松地正确设置SoapHeader。