带有 PHP 的 SOAP 请求和响应(显示响应)

SOAP request and repsonse with PHP (display response)

我需要发出 SOAP 请求并获得响应,但我不知道 SOAP 是如何工作的。我试图搜索它,一切都是如此混乱。

我需要像这样在这里进行身份验证请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dir="http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService">
   <soapenv:Header/>
      <soapenv:Body>
        <dir:Authenticate>
           <!-- Optional: -->
           <dir:authenticateRequest BranchCode="abcde" UserName="user" Password="password" Application="application" Client="?">
           <dir:BranchID>1</dir:BranchID>
        </dir:authenticateRequest>
      </dir:Authenticate>
  </soapenv:Body>
</soapenv:Envelope>

然后得到回复,但不知道该怎么做。我搜索并发现了一些类似的问题,但没有得到任何回应。

我正在做的是这个:

$send = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dir="http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService">
        <soapenv:Header/>
            <soapenv:Body>
                <dir:Authenticate>
                <!-- Optional: -->
                <dir:authenticateRequest BranchCode="abcde" UserName="user" Password="password" Application="application" Client="?">
                    <dir:BranchID>1</dir:BranchID>
                </dir:authenticateRequest>
            </dir:Authenticate>
        </soapenv:Body>
     </soapenv:Envelope>';


 $soapUrl ="http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?singleWsdl";
      $soapClientVar = new SoapClient("http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?singleWsdl"); 

 $resp = $soapClientVar->Authenticate($send);

 var_dump($resp);

我知道 99% 我完全错了我应该做什么。有人可以帮助我了解我到底应该做什么并使这个 SOAP 工作吗?

TIA

WSDL 设置 SoapClient:

http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?singleWsdl

并告诉客户在调用 SOAP 服务的方法方面期望什么。 SoapClient 负责创建您在 $send.

中看到的内容

您无需发送原始 SOAP(SoapClient 将为您完成),而是在方法级别工作。从 WSDL 中,Authenticate() 方法采用类型为 tns:AuthenticateRequest 的参数,其中包含 BranchCodeUserName 等,以及 returns 类型为 tns:AuthenticateResponse 的对象,包含 tns:ResultBase 其中包含实际结果 SuccessNarrative

这可能会让您找到解决方案:

$soapClientVar = new SoapClient("http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?singleWsdl"); 
$params = array(
  "BranchCode" => $BranchCode,
  "UserName" => $UserName,
  "Password" => $Password,
  "Application" => $Application,
  "Client" => $Client
);
$response = $soapClientVar->__soapCall("Authenticate", array($params));