SOAP Header Authentication

When importing a SOAP web service in Appway using a WSDL and XSD, how do you set up header authentication?

This service requires a WS-Security UsernameToken authentication, which then needs to be added in the header of the call. Here are the steps to follow:

Step 1: Create a SoapHeader object

Define a function to create a SoapHeader object with the required information

Copy
Function WS_GenerateAuthSoapHeader(String $username, String $password) : SoapHeaderElement Begin
   SoapHeaderElement $header := new SoapHeaderElement;
   StringBuilder $headerXmlString := new StringBuilder;
   $headerXmlString.append('<wsse:Security ');
   $headerXmlString.append('xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" ');
   $headerXmlString.append('xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"> ');
   $headerXmlString.append('<wsse:UsernameToken wsu:Id=\"UsernameToken-11\"> ');
   $headerXmlString.append('<wsse:Username>');
   $headerXmlString.append($username);
   $headerXmlString.append('</wsse:Username> ');
   $headerXmlString.append('<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">');
   $headerXmlString.append($password);
   $headerXmlString.append('</wsse:Password> </wsse:UsernameToken> </wsse:Security>');
   $header.element := $headerXmlString.toString();
   Return $header;
End

Step 2: Define Wrapper class

A CLIENT data class was created by the WebService extension upon importing the WSDL. In order to avoid losing your changes any time you reimport the WSDL, define a Wrapper data class that extends the CLIENT data class created by the extension.

Step 3: Define the constructor

Define the constructor of the Wrapper data class in order to add the SOAP header:

Copy
Function NEW(String $serviceEndpoint := null, String $userId := null, String $password := null) : Nothing Begin
   $super.NEW($serviceEndpoint, $userId, $password);
   $this.addSoapHeader(WS_GenerateAuthSoapHeader($userId, $password));
End