0

I have following soap response. How can i call soap using php.Any Idea. Thanks in Advance.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">
         <wsse:UsernameToken>
            <wsse:Username>XXXXXXXXXXXX</wsse:Username>
            <wsse:Password>XXXXXXXXXXXXXXXXX</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soap:Header>
   <soapenv:Body>
      <cus1:GetCustomerDetailsRequest xmlns:cus1="XXXXXXXXXXXXXXXXXXXXXXX" xmlns:com="XXXXXXXXXXXXXXXXXXXXXXXX" xmlns:cus="XXXXXXXXXXXXXXXXX">
         <cus:GetCustomerDetails>
            <AccountMSISDN>1234567890</AccountMSISDN>
         </cus:GetCustomerDetails>
      </cus1:GetCustomerDetailsRequest>
   </soapenv:Body>
</soapenv:Envelope>
Marcel Burkhard
  • 3,453
  • 1
  • 29
  • 35
Puneet
  • 615
  • 3
  • 9
  • 23
  • possible duplicate of [converting SOAP XML response to a PHP object or array](http://stackoverflow.com/questions/15892639/converting-soap-xml-response-to-a-php-object-or-array) – Shankar Narayana Damodaran Apr 26 '14 at 05:58

2 Answers2

2

You should be able to have a play around with the fields, parameters and methods you need by using a free online soap tool like this:

http://www.soapclient.com/soaptest.html

Also, you should have a look at this answer: SOAP request in PHP with CURL

Community
  • 1
  • 1
1
$soapUrl = "http://www.example.com/masterdata/masterdata.asmx?wsdl";

$soapUser = "username";  //  username

$soapPassword = "password"; // password

// xml post structure

$xml_post_string = 'soap string';   // data from the form, e.g. some ID number

$headers = array(
          "Content-type: text/xml;charset=\"utf-8\"",
          "Accept: text/xml",
          "Cache-Control: no-cache",
          "Pragma: no-cache",
          "SOAPAction: http://tempuri.org/GetMasterData", 
          "Content-length: ".strlen($xml_post_string),
      ); //SOAPAction: your op URL

$url = $soapUrl;

// PHP cURL  for https connection with auth
$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

curl_setopt($ch, CURLOPT_TIMEOUT, 10);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

// converting
$response = curl_exec($ch); 

curl_close($ch);

    // a new dom object 
 $dom = new domDocument('1.0', 'utf-8'); 

 // load the html into the object 
 $dom->loadXml($response);         

 $array = json_decode($dom->textContent,TRUE);

  print_r($array);
AntonioGarcía
  • 1,140
  • 2
  • 15
  • 25
  • I have tried your way but unable to get desired results can you please see my [question](https://stackoverflow.com/questions/55980022/unable-to-convert-soap-response-string-to-xml-in-yii2)? – Moeez May 09 '19 at 17:13