我尝试创建SOAP请求但无法成功。 SOAP WADL网址为http://www.mobipost.com.au/httpapi/Messaging.asmx?WSDL
AND请求应该是:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthenticationHeader xmlns="http://messaging.mobipostapi.thirdscreen.com.au/">
<UserName>SAMPLE_USER</UserName>
<Password>SAMPLE_PASS</Password>
</AuthenticationHeader>
</soap:Header>
<soap:Body>
<SendSMSToContacts xmlns="http://messaging.mobipostapi.thirdscreen.com.au/">
<oSMS>
<MessageText>THIS IS MESSAGE</MessageText>
</oSMS>
<ContactIDs>
<int>123456789</int>
<int>987654321</int>
</ContactIDs>
</SendSMSToContacts>
</soap:Body>
</soap:Envelope>
我试过了:
$url = 'http://www.mobipost.com.au/httpapi/Messaging.asmx?WSDL';
$client = new SoapClient($url);
$result = $client->AuthenticationHeader(array('UserName' => 'SAMPLE_USER','Password' => 'SAMPLE_PASS'));
$result = $client->SendSMSToContacts(array('MessageText' => 'THIS IS MESSAGE'));
$result = $client->ContactIDs(array('123456789', '987654321'));
但它显示错误:
Fatal error: Uncaught SoapFault exception: [Client] Function ("AuthenticationHeader") is not a valid method for this service in D:\xampp\htdocs\globalmobile\send_message_v2.php:26 Stack trace: #0 D:\xampp\htdocs\globalmobile\send_message_v2.php(26): SoapClient->__call('AuthenticationH...', Array) #1 D:\xampp\htdocs\globalmobile\send_message_v2.php(26): SoapClient->AuthenticationHeader(Array) #2 {main} thrown in D:\xampp\htdocs\globalmobile\send_message_v2.php on line 26
是否可以帮助我创建有效的SOAP请求以与WSDL服务器进行通信。
提前谢谢。
答案 0 :(得分:0)
必须只有一个请求,您发送三个。 你必须创建这样的东西:
1)设置用于身份验证的标头:
$auth = $auth = new SOAPAuth('USERNAME', 'PASSWORD');
$header = new SOAPHeader('urn:example.org/auth', 'AuthenticationHeader', $auth);
$client->__setSoapHeaders($header);
2)使用消息文本和联系人创建创建请求。
$result = $client->SendSMSToContacts(array("MessageText" => "some text", "contactIDs" => array(123456789, 123456789));
P.S。对于调试创建客户端:
$client = new SoapClient($url, array('trace' => 1,
'exceptions' => 1,));
在发送请求后,查看已发送并在其上重新发出的请求:
var_dump("REQUEST=", $client->__getLastRequest());
var_dump("RESPONSE=", $client->__getLastResponse());