Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL loXml
LOCAL loDt
LOCAL lnBLocal
LOCAL lcCreated
LOCAL loWsse1
LOCAL loWsse2
LOCAL loXHeader

* 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:
loXml = CreateObject('Chilkat.Xml')
loXml.Tag = "soap:Envelope"
loXml.AddAttribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/")
loXml.UpdateChildContent("soap:Header","")
loXml.UpdateAttrAt("soap:Body|getHello",1,"xmlns","http://www.oracle.com")

* Get the current date/time in a string with this format: 2004-05-19T08:46:04Z
loDt = CreateObject('Chilkat.CkDateTime')
loDt.SetFromCurrentSystemTime()
lnBLocal = 0
lcCreated = loDt.GetAsTimestamp(lnBLocal)

* Now build each UsernameToken block:
loWsse1 = CreateObject('Chilkat.Xml')
loWsse1.Tag = "wsse:Security"
loWsse1.AddAttribute("xmlns:wsse","http://schemas.xmlsoap.org/ws/2003/06/secext")
loWsse1.UpdateAttrAt("wsse:UsernameToken",1,"wsu:Id","sample")
loWsse1.UpdateAttrAt("wsse:UsernameToken",1,"xmlns:wsu","http://schemas.xmlsoap.org/ws/2003/06/utility")
loWsse1.UpdateChildContent("wsse:UsernameToken|wsse:Username","sample")
loWsse1.UpdateAttrAt("wsse:UsernameToken|wsse:Password",1,"Type","wsse:PasswordText")
loWsse1.UpdateChildContent("wsse:UsernameToken|wsse:Password","oracle")
loWsse1.UpdateChildContent("wsse:UsernameToken|wsu:Created",lcCreated)

loWsse2 = CreateObject('Chilkat.Xml')
loWsse2.Tag = "wsse:Security"
loWsse2.AddAttribute("soap:actor","oracle")
loWsse2.AddAttribute("xmlns:wsse","http://schemas.xmlsoap.org/ws/2003/06/secext")
loWsse2.UpdateAttrAt("wsse:UsernameToken",1,"wsu:Id","oracle")
loWsse2.UpdateAttrAt("wsse:UsernameToken",1,"xmlns:wsu","http://schemas.xmlsoap.org/ws/2003/06/utility")
loWsse2.UpdateChildContent("wsse:UsernameToken|wsse:Username","oracle")
loWsse2.UpdateAttrAt("wsse:UsernameToken|wsse:Password",1,"Type","wsse:PasswordText")
loWsse2.UpdateChildContent("wsse:UsernameToken|wsse:Password","oracle")
loWsse2.UpdateChildContent("wsse:UsernameToken|wsu:Created",lcCreated)

* Insert the UsernameToken blocks:
loXHeader = loXml.GetChildWithTag("soap:Header")
loXHeader.AddChildTree(loWsse1)
loXHeader.AddChildTree(loWsse2)
RELEASE loXHeader

* Show the XML:
? loXml.GetXml()

RELEASE loXml
RELEASE loDt
RELEASE loWsse1
RELEASE loWsse2