Maria
Maria

Reputation: 760

SOAP request and repsonse with PHP (display response)

I need to make a SOAP request and get a response back, but I have no idea how SOAP works. I tried to search for it and everything is so confusing.

I need to make an authentication request here like this :

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

And get an response after that, but have no idea how to do it. I searched and found some similar questions, but can not get any response.

What I am doing is this :

$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);

I know that 99% I totally wrong of what should I do. Can someone please help me understand what exactly should I do and make this SOAP work?

TIA

Upvotes: 1

Views: 1208

Answers (1)

codebrane
codebrane

Reputation: 4620

The WSDL sets up the SoapClient:

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

and tells the client what to expect in terms of methods to call on the SOAP service. SoapClient takes care of creating what you see in $send.

Instead of sending raw SOAP (which SoapClient will do for you), you work at the method level. From the WSDL the Authenticate() method takes a parameter of type tns:AuthenticateRequest which contains BranchCode, UserName etc. and returns an object of type tns:AuthenticateResponse, containing tns:ResultBase which contains the actual result Success, Narrative etc.

this might get you towards your solution:

$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));

Upvotes: 1

Related Questions