Monday, April 16, 2012

Soap call using curl in php

$xml = '<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing/" xmlns:xsd="http://www.w3.org/2001/XMLSchema/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance/">
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<wsse:Security soap:mustUnderstand="1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
</wsse:Security>
</soapenv:Header>
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<EnRequest xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/EnrollRequest.V1">
<EnRequestDS>
<CG_ENR_REQST class="R" xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/EnRequestDS.V1">
<PERSON_ID>2</PERSON_ID>
</CG_ENR_REQST>
</EnRequestDS>
</EnRequest>
</soapenv:Body>
</soapenv:Envelope>';

$wsdlurl = http://192.162.10.4:8080/test/conector

$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Transfer-Encoding:chunked",
"SOAPAction: \"EnrRqst.v1\"",
"Content-length: ".strlen($xml),
);

$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $wsdlurl );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xml);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
$ers = curl_exec($soap_do);


* Change soap action in $header based on your need.