Delphi DLL
Delphi DLL
SOAP WS-Security Username Authentication
See more XML Examples
Demonstrates creating SOAP XML for WS-Security Username Authentication. The client user name and password are encapsulated in a WS-Security <wsse:UsernameToken>.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, CkDateTime, Xml;
...
procedure TForm1.Button1Click(Sender: TObject);
var
xml: HCkXml;
dt: HCkDateTime;
bLocal: Boolean;
created: PWideChar;
wsse1: HCkXml;
wsse2: HCkXml;
xHeader: HCkXml;
begin
// Generate this XML with the code that follows:
// <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
// <soap:Header>
// <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
// <wsse:UsernameToken wsu:Id="sample"
// xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
// <wsse:Username>sample</wsse:Username>
// <wsse:Password Type="wsse:PasswordText">oracle</wsse:Password>
// <wsu:Created>2004-05-19T08:44:51Z</wsu:Created>
// </wsse:UsernameToken>
// </wsse:Security>
// <wsse:Security soap:actor="oracle"
// xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
// <wsse:UsernameToken wsu:Id="oracle"
// xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
// <wsse:Username>myUsername</wsse:Username>
// <wsse:Password Type="wsse:PasswordText">myPassword</wsse:Password>
// <wsu:Created>2004-05-19T08:46:04Z</wsu:Created>
// </wsse:UsernameToken>
// </wsse:Security>
// </soap:Header>
// <soap:Body>
// <getHello xmlns="http://www.oracle.com"/>
// </soap:Body>
// </soap:Envelope>
//
// First build the outer housing:
xml := CkXml_Create();
CkXml_putTag(xml,'soap:Envelope');
CkXml_AddAttribute(xml,'xmlns:soap','http://schemas.xmlsoap.org/soap/envelope/');
CkXml_UpdateChildContent(xml,'soap:Header','');
CkXml_UpdateAttrAt(xml,'soap:Body|getHello',True,'xmlns','http://www.oracle.com');
// Get the current date/time in a string with this format: 2004-05-19T08:46:04Z
dt := CkDateTime_Create();
CkDateTime_SetFromCurrentSystemTime(dt);
bLocal := False;
created := CkDateTime__getAsTimestamp(dt,bLocal);
// Now build each UsernameToken block:
wsse1 := CkXml_Create();
CkXml_putTag(wsse1,'wsse:Security');
CkXml_AddAttribute(wsse1,'xmlns:wsse','http://schemas.xmlsoap.org/ws/2003/06/secext');
CkXml_UpdateAttrAt(wsse1,'wsse:UsernameToken',True,'wsu:Id','sample');
CkXml_UpdateAttrAt(wsse1,'wsse:UsernameToken',True,'xmlns:wsu','http://schemas.xmlsoap.org/ws/2003/06/utility');
CkXml_UpdateChildContent(wsse1,'wsse:UsernameToken|wsse:Username','sample');
CkXml_UpdateAttrAt(wsse1,'wsse:UsernameToken|wsse:Password',True,'Type','wsse:PasswordText');
CkXml_UpdateChildContent(wsse1,'wsse:UsernameToken|wsse:Password','oracle');
CkXml_UpdateChildContent(wsse1,'wsse:UsernameToken|wsu:Created',created);
wsse2 := CkXml_Create();
CkXml_putTag(wsse2,'wsse:Security');
CkXml_AddAttribute(wsse2,'soap:actor','oracle');
CkXml_AddAttribute(wsse2,'xmlns:wsse','http://schemas.xmlsoap.org/ws/2003/06/secext');
CkXml_UpdateAttrAt(wsse2,'wsse:UsernameToken',True,'wsu:Id','oracle');
CkXml_UpdateAttrAt(wsse2,'wsse:UsernameToken',True,'xmlns:wsu','http://schemas.xmlsoap.org/ws/2003/06/utility');
CkXml_UpdateChildContent(wsse2,'wsse:UsernameToken|wsse:Username','oracle');
CkXml_UpdateAttrAt(wsse2,'wsse:UsernameToken|wsse:Password',True,'Type','wsse:PasswordText');
CkXml_UpdateChildContent(wsse2,'wsse:UsernameToken|wsse:Password','oracle');
CkXml_UpdateChildContent(wsse2,'wsse:UsernameToken|wsu:Created',created);
// Insert the UsernameToken blocks:
xHeader := CkXml_GetChildWithTag(xml,'soap:Header');
CkXml_AddChildTree(xHeader,wsse1);
CkXml_AddChildTree(xHeader,wsse2);
CkXml_Dispose(xHeader);
// Show the XML:
Memo1.Lines.Add(CkXml__getXml(xml));
CkXml_Dispose(xml);
CkDateTime_Dispose(dt);
CkXml_Dispose(wsse1);
CkXml_Dispose(wsse2);
end;