note 97273 added to soapclient.soapclient
| From: | bhargav dot khatana at gmail dot com | Date: | Sun, 11 Apr 2010 18:10:21 +0000 |
| Subject: | note 97273 added to soapclient.soapclient | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168137@lists.php.net to get a copy of this message | ||
It took me longer than a week to figure out how to implement WSSE (Web Service Security) headers in
native PHP SOAP. There are no much resource available on this, so thought to add this here for
community benefit.
Step1: Create two classes to create a structure for WSSE headers
class clsWSSEAuth {
private $Username;
private $Password;
function __construct($username, $password) {
$this->Username=$username;
$this->Password=$password;
}
}
class clsWSSEToken {
private $UsernameToken;
function __construct ($innerVal){
$this->UsernameToken = $innerVal;
}
}
Step2: Create Soap Variables for UserName and Password
$username = 1111;
$password = 1111;
//Check with your provider which security name-space they are using.
$strWSSENS = "http://schemas.xmlsoap.org/ws/2002/07/secext";
$objSoapVarUser = new SoapVar($username, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
$objSoapVarPass = new SoapVar($password, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
Step3: Create Object for Auth Class and pass in soap var
$objWSSEAuth = new clsWSSEAuth($objSoapVarUser, $objSoapVarPass);
Step4: Create SoapVar out of object of Auth class
$objSoapVarWSSEAuth = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS,
'UsernameToken', $strWSSENS);
Step5: Create object for Token Class
$objWSSEToken = new clsWSSEToken($objSoapVarWSSEAuth);
Step6: Create SoapVar out of object of Token class
$objSoapVarWSSEToken = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS,
'UsernameToken', $strWSSENS);
Step7: Create SoapVar for 'Security' node
$objSoapVarHeaderVal=new SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS,
'Security', $strWSSENS);
Step8: Create header object out of security soapvar
$objSoapVarWSSEHeader = new SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal,true,
'http://abce.com');
//Third parameter here makes 'mustUnderstand=1
//Forth parameter generates 'actor="http://abce.com"'
Step9: Create object of Soap Client
$objClient = new SoapClient($WSDL, $arrOptions);
Step10: Set headers for soapclient object
$objClient->__setSoapHeaders(array($objSoapVarWSSEHeader));
Step 11: Final call to method
$objResponse = $objClient->__soapCall($strMethod, $requestPayloadString);
----
Server IP: 69.147.83.197
Probable Submitter: 206.210.27.33
----
Manual Page -- http://www.php.net/manual/en/soapclient.soapclient.php
Edit -- https://master.php.net/note/edit/97273
Del: integrated -- https://master.php.net/note/delete/97273/integrated
Del: useless -- https://master.php.net/note/delete/97273/useless
Del: bad code -- https://master.php.net/note/delete/97273/bad+code
Del: spam -- https://master.php.net/note/delete/97273/spam
Del: non-english -- https://master.php.net/note/delete/97273/non-english
Del: in docs -- https://master.php.net/note/delete/97273/in+docs
Del: other reasons-- https://master.php.net/note/delete/97273
Reject -- https://master.php.net/note/reject/97273
Search -- https://master.php.net/manage/user-notes.php