Simple way to access soap api with examples

Soap : Stands for Simple Object Access Protocal

Purpouse : To transfer the data from one application to another application

Under Standing Soap Elements

→ 1. Envelope : means to identifies the XML document as a SOAP message. Envelope is mandatory

→ 2. Header : contains header infomartion. Header is optional usually contains information relevant to authentication the soap protocal doesn’t provide any authentication. if You want You need to add security purpouse in header tag. check for below example.

Authenticate
Username
password
Authenticate

Don’t forget before and after tags < >

→ 3. Body : contains request and responce infomartion

Structure Of Soap Message

Soap xml structure

Simple way to connect Soap Api with php examples

Soap is deafult functionalty in php no need to include any external file.

If you’re not Enable Soap, you can check your phpinfo file and enable It. .

Php Soap callining in php example code

$wsdlUrl = "http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.wsdl";
$soapUrl = new SoapClient($wsdlUrl);
$params  = array("username" => "username", "password" => "password");
$result  = $soapUrl->apiMethodeName($params);
print_r($result);

Soap Request with Codeigniter example code

application/controllers In controller we need to create home.php file and then copy and paste below code. Edit your wsdl url and your username password and methode name

class Home extends CI_controller{
	public function __construct(){
		parent::__construct();
		$wsdlUrl = "http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.wsdl";
		$this->client = new SoapClient($wsdlUrl);        
		$this->params = array( 'username'  => 'apiUsername','password' => 'apiPassword');
	}
	public function index()
	{
		$result = $this->client->apiMethodName($this->params) ;
		print_r($result);
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *