GnuDeveloper.com

Web Service using SOAP

Simple Object Access Protocol(SOAP) provides communicate between applications is over HTTP protocol. The communication of request and response by the xml data.

prerequisite PHP Extension are
XML ,SOAP, XSL

Web services approach has 2 component
1. Service Provider (Service provider)
2. Service requester (Service Consumer)

The SOAP communication is done by pure xml structure as follows

The simple authentication are illustrated as follows
The Full Source Code

Service consumer(Soap Client):
It just invoke the web service implemented by the service provider.
It has soap client where it can connection can be made and in the do request method ,we can mention th endpoint url and request url.

<?php
$url
='http://127.0.0.1/soap/authentication/SoapServer.php'
$request getSoapAuthenticateRequestXML('vivekanandan','newpwd123');
$client = new SoapClient(null,array(location=>$url,uri=>$url,'exceptions'=>FALSE,'trace'=>true));
$xmlstr $client->__doRequest($request,$url,"",1);
print 
$xmlstr;  
?>

Request XML:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<SOAP-ENV:Body>
<UserCredentialRequest>
        <Username>vivekanandan</Username>
        <Password>123456</Password>
</UserCredentialRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 

Service Provider(Soap Server):
It implements the web service. Web Services Description Language(Wsdl) file is a xml document which describe Web services. Each and every SOAP request and SOAP response
Has wel defined in the wsdl file .
WSDL
It created soapserver with the wsdl so that all the soap client request will be checked with the wsdl and corrensponding mentod will be called.

Depends upon the request xml the wsdl will be checked In the top to bottom manner.so that finally from service tag the corresponding operation or function will be called.

Soap Request :
Message -> portType -> binding -> service
Message -> complexType -> UserCredentialRequest

<?php
class UserAuthentication {
    function 
__construct(){
    }
    public function 
AuthendicateUserInfo($reqData){
     if(
$reqData->Username=='vivekanandan' &&  $reqData->Password=='123456'){
         
$vResponseText ='Valid';
     }else {
         
$vResponseText 'Invalid';
     } 
    
$vResponseText "<UserCredentialResponse><Status>".$vResponseText."</Status></UserCredentialResponse>";
    
$outData = new SoapVar($vResponseTextXSD_ANYXML"Response"nullnull);    
    return 
$outData;            
    }        

  
$server = new SoapServer("UserAuthentication.wsdl");
$server->setClass("UserAuthentication");
$server->handle();
?>

After the operation or function is executed , then the soap framework will lookup for the response to the soap client
Soap Response:
Message -> portType -> binding -> service
Message -> complexType -> UserCredentialResponse

SOAP Response XML

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<UserCredentialResponse>
         <Status>Valid</Status>
</UserCredentialResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Groups: