I have my PHP code to deal with SOAP, it works fine when I request data from WSDL with no security required. But when I use the same code for a WSDL which requires security header, it shows an error.
The error is:
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] No WS-Security header found in C:\wamp\www\testing.php:6 Stack trace: #0
My code is as below.
<?php $requestParams = array(
'SkuCode' => 'SKUCode'
);
$client = new SoapClient('https://somethinghere.unicommerce.com/services/soap/somethinghere.wsdl');
$response = $client->GetItemType($requestParams);
print_r($response);
?>
so where do i need to put the security header? since this code is working fine i believe I only need to add security headers somewhere in this code.
UPDATE:
<?php
try {
$security = array(
'Username'=>'myusername',
'Password'=>'GSKJHUE87SFJFHSDKF78632BDBFG=',
'Nonc'=> '7D8SDFKJSDHF678SKDJFHSD==',
'Created' => '2015-01-03T04:16:42.757Z',
'UsernameToken' => '876SXVASDFS876BC876CVB876'
);
$header = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','Security',$security, false);
$client = new SoapClient('https://myaccountwith.unicommerce.com/services/soap/uniware18.wsdl');
$client->__setSoapHeaders($header);
$params = new stdClass();
$params->GetItemType = new stdClass();
$params->SkuCode = 'ATSC221';
$result = $client->__soapCall('GetItemType', array($params, null, $header));
print_r($result);
} catch (SoapFault $e) {
die($e->getMessage());
}
?>
The following code outputs the below
No WS-Security header found