Example of PHP code for creating a SOAP HEADER

Here is an example in PHP for creating a SOAP header:

//Generating a header
	
	$client = new soapClient("https://secure.lyra.com/vads-ws/v5?wsdl", $options = array(
			'trace'=>1, 
			'exceptions'=> 0, 			
			'encoding' => 'UTF-8',
			'soapaction' => '')
		);	

	//Calculating values transmitted in the header	

	$ns = 'http://v5.ws.vads.lyra.com/Header/';					
	$shopId = "12345678";
	$requestId = gen_uuid();
	$timestamp = gmdate("Y-m-d\TH:i:s\Z");
	$mode = "TEST";
	$authToken = base64_encode(hash_hmac('sha256',$requestId.$timestamp, $key, true));		
				
	//Creating the shopId, requestId, timestamp, mode et authToken headers
		
	$headerShopId = new SOAPHeader($ns, 'shopId', $shopId);
	$headerRequestId = new SOAPHeader($ns, 'requestId', $requestId);
	$headerTimestamp = new SOAPHeader($ns, 'timestamp', $timestamp);
	$headerMode = new SOAPHeader($ns, 'mode', $mode);
	$headerAuthToken = new SOAPHeader($ns, 'authToken', $authToken);
				
	//Adding headers into the SOAP Header
		
	$headers = array(
		$headerShopId,
		$headerRequestId,
		$headerTimestamp,
		$headerMode,
		$headerAuthToken 
	);
	
$client->__setSoapHeaders($headers);

Various examples of code in different programming languages are available on the Internet.

  • JAVA

http://www.mkyong.com/webservices/jax-ws/jax-ws-soap-handler-in-client-side/

  • Visual Basic .NET

https://msdn.microsoft.com/en-fr/library/vstudio/whew6x7f(v=vs.100).aspx

http://forums.asp.net/t/1137408.aspx?Adding+information+to+the+SOAP+Header