0

我被要求研究使用 SOAP 服务同步数据。我根本不是很了解 SOAP,我得到了一个错误的请求错误。

我试图调用的函数是一个测试回显函数:

公共字符串 EchoAuthenticated(字符串文本)

每次我调用它时都会出错。

我已经注释掉了用户名/密码设置,因为我现在不知道用户名和密码,而且我的联系人正在休假:(虽然现在我很高兴收到身份验证失败的消息而不是错误...

如果有人可以在这里指出我正确的方向,请...

谢谢,

约翰

 <?php

 $apiUrl         = 'https://exdev.api.propctrl.co.za/v3/Integration.svc?wsdl';
 $options        = array( 'trace' => 1, 'exceptions' => 1,  'soap_version' => SOAP_1_2);

 try
 {
    $client     = new SoapClient($apiUrl, $options);

    //$data       = array(
    //  'Username'          => "test",
    //  'Password'          => "test"
    //);

    //$header = new SoapHeader('https://exdev.api.propctrl.co.za/v3/', 'CredentialsHeader', $data, false);
    //$client->__setSoapHeaders($header);

    var_dump($client->__getFunctions());


    print $client->EchoAuthenticated("Test String");
    var_dump($client->__getLastRequest());

 }
 catch(Exception $e)
 {
    echo $e->getMessage();
 }

 ?>
4

1 回答 1

0

您可以尝试以下方法:

...
$client     = new SoapClient($apiUrl, $options);

var_dump($client->__getFunctions());

$auth = array("Username" => "John", "Password" => "secret", 
    "IsP24Credentials" => false);
$header = new SoapHeader("https://www.propctrl.com/", "CredentialsHeader", 
    $auth, FALSE);
$client->__setSoapHeaders($header);

print $client->EchoAuthenticated(array( 
    "text" => "My text to be echoed."
));
var_dump($client->__getLastRequest());
...

这应该会产生如下所示的请求 SOAP 请求:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="https://www.propctrl.com/v3" xmlns:ns2="https://www.propctrl.com/">
   <env:Header>
      <ns2:CredentialsHeader>
         <ns2:IsP24Credentials>false</ns2:IsP24Credentials>
         <ns2:Password>secret</ns2:Password>
         <ns2:Username>John</ns2:Username>
      </ns2:CredentialsHeader>
   </env:Header>
   <env:Body>
      <ns1:EchoAuthenticated>
         <ns1:text>My text to be echoed.</ns1:text>
      </ns1:EchoAuthenticated>
   </env:Body>
</env:Envelope>

作为旁注,您可以查看http://www.soapui.org/。该工具对 Web 服务开发有很大帮助。

于 2013-03-27T11:05:03.237 回答