PHP: SOAP and WSS

$ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
 
$token = new stdClass;
$token->Username = new SoapVar('username', XSD_STRING, null, $ns, null, $ns);
$token->Password = new SoapVar('password', XSD_STRING, null, $ns, null, $ns);
 
$wsec = new stdClass;
$wsec->UsernameToken = new SoapVar($token, SOAP_ENC_OBJECT, null, $ns, null, $ns);
 
$header = new SoapHeader($ns, 'Security', $wsec, true);
 
// Soap environment
$soapurl = 'http://www.domain.com/webservice.wsdl';
 
try {
	$soapclient = new SoapClient($soapurl, array("trace"=>1));
	// Set WSS authentication header	
	$soapclient->__setSoapHeaders($header);
} catch (SoapFault $fault) {
	echo "Soap error";
}

Leave a Reply