使用PHP创建SOAP标头

时间:2014-07-21 22:25:45

标签: php soap wsdl soap-client

我是SOAP的新用户,我无法使用以下模板了解如何创建SOAP header

我使用SoapClient在PHP中编程。

 <SOAP-ENV:Header>
    <Username xmlns="http://something.com/WebServices/SMSPush">User</Username>
    <Password xmlns="http://something.com/WebServices/SMSPush">Pass</Password>
    <To SOAP-ENV:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://wsmcg002.something.sys:8004/SmsPushService.svc</To>
    <Action SOAP-ENV:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">SendMultipleTextMessage</Action>
</SOAP-ENV:Header>

1 个答案:

答案 0 :(得分:2)

使用SoapHeader

设置SOAP标头
<?php
$client = new SoapClient(...);

$headers = array();
$headers[] = new SoapHeader('http://something.com/WebServices/SMSPush', 'Username', 'Usser');
$headers[] = new SoapHeader('http://something.com/WebServices/SMSPush', 'Password', 'Pass');
$headers[] = new SoapHeader('http://schemas.microsoft.com/ws/2005/05/addressing/none', 'To', 'http://wsmcg002.something.sys:8004/SmsPushService.svc', true);
$headers[] = new SoapHeader('http://schemas.microsoft.com/ws/2005/05/addressing/none', 'Action', 'SendMultipleTextMessage', true);
$client->__setSoapHeaders($headers);