使用PHP创建SOAP报头


create SOAP header using PHP

我是SOAP的新手,我不知道如何使用以下模板创建SOAP header:

我在PHP编程使用SoapClient。

 <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>

您使用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);