使用PHP的SOAP请求和repsonse(显示响应)

时间:2018-03-15 15:01:47

标签: php xml soap soap-client

我需要发出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

1 个答案:

答案 0 :(得分:1)

WSDL设置SoapClient:

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

并告诉客户端在调用SOAP服务的方法方面会发生什么。 SoapClient负责创建您在$send中看到的内容。

您可以在方法级别工作,而不是发送原始SOAP(SoapClient将为您执行的操作)。在Authenticate()方法中,tns:AuthenticateRequest方法采用BranchCode类型的参数,其中包含UserNametns:AuthenticateResponse等,并返回类型为tns:ResultBase的对象,其中包含{{ 1}}包含实际结果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));