SOAP – Simple Object Access Protocol.it uses the only XML for exchanging information From the client-side to the server-side. we can use any of the languages to consume this api.there is no language dependency. you can use any internet protocol like TCP, UDP. also soap API use user-defined Https codes. these APIs are more secure than other APIs. so that mostly used by the banking industry.
In this, We will use soap API with
SOAP API with the Postman
Step 1. Download and install the postman
Step 2. We will use this http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL
soap API for testing
Step 3. Request data for this API
<pre>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<ListOfContinentsByName xmlns="http://www.oorsprong.org/websamples.countryinfo"/>
</Body>
</Envelope>
</pre>
If you unable to produce the request data add this chrome extension wizdler
Click on ListOfCountryByName. you will redirect on the new tab then copy the request data.
Step 4. Then a select method to Post
Step 5. Add content type in the header to text/XML
Step 6. Welldone All set now press the send button and we will the response in XML formate from your soap API.
Calling soap api using the PHP
For consuming the soap API in PHP we will use the predefined curl method
To call this API in PHP by curl method you have to set these parameters
CURLOPT_URL=>” ”
CURLOPT_POSTFIELDS =>” ”
CURLOPT_HTTPHEADER =>” ”
This is the demo code for reference. past this code into your project and remember pls change the CURLOPT_URL and CURLOPT_POSTFIELDS
<pre>
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>
"<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">
<Body>
<ListOfContinentsByCode xmlns=\"http://www.oorsprong.org/websamples.countryinfo\"/>
</Body>
</Envelope>",
CURLOPT_HTTPHEADER => array("content-type: text/xml"),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
</pre>
//call soap API in php
Make index.php into your project and try to access this file in the browser. Make sure you have made this project into the localhost root directory.
I wish to learn Mobile App Development!