2

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
Nasir Zia
  • 564
  • 1
  • 6
  • 20
  • Is that the real production url? Because that URL outputs an HTML page and not an WSDL (XML) file – Raymond Nijland Sep 04 '15 at 05:41
  • I have changed the URL before posting here because i am not allowed to share the actualy URL, The original URL is actually an XML Format document and not HTML page. – Nasir Zia Sep 04 '15 at 05:45
  • Contact them and ask or look in de API docs how WS-Security header need to be generated most likly this some kind of hash. – Raymond Nijland Sep 04 '15 at 05:47
  • 1
    Maybe this helps http://stackoverflow.com/questions/953639/connecting-to-ws-security-protected-web-service-with-php try the SoapClient extension code – Raymond Nijland Sep 04 '15 at 05:53

0 Answers0