Batman Batman - 7 months ago 47
PHP Question

Soap Client in PHP

Hi Can anyone explain me in implementing below SOAP XML in PHP, I saw some questions they were handled using CURL but I want to use SoapClient library in PHP Can anyone help me.

I saw some people used below code in PHP get the simple SOAP , How can I implement the same way in my code

//Create the client object
$soapclient = new SoapClient('');

//Use the functions of the client, the params of the function are in
//the associative array
$params = array(
'locationID' => '19087525238255',
'custFirstName' => 'Seure',
'custLastName' => 'Install',
'customerType' => 'RESI'
$response = $soapclient->octService($params);




<soapenv:Envelope xmlns:soapenv = "" xmlns:com = "">


I not able to achieve using CURL POST.

Here important thing is SOAPAction which you can use in the WSDL document

    $headers = array(
     "Accept-Encoding: gzip,deflate",
     "Content-Type: text",
     "Cache-Control: no-cache",
     "Username: yourusername",
     "Password: password",                 
     "SOAPAction: urn:OCTService", 
     "Content-length: ".strlen($xml_post_string),
     ); //SOAPAction: your op URL

     $ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
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_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); 
echo $response;

// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);

// convertingc to XML
$parser = simplexml_load_string($response2);