Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) HTTP request for a SOAP web service using WS-Security 1.0 with a digital certificate for authenticationSee more HTTP ExamplesDemonstrates how to build and send an HTTP request for a SOAP web service using WS-Security 1.0 with a digital certificate for authentication.
; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. ; See HTTP request for a SOAP web service using WS-Security 1.0 with a digital certificate for authentication ; ------------------------------------ ; Step 1: Load the signing certificate ; ------------------------------------ $oCert = ObjCreate("Chilkat.Cert") Local $bSuccess = $oCert.LoadFromSmartcard("") If ($bSuccess = False) Then ConsoleWrite($oCert.LastErrorText & @CRLF) Exit EndIf ; --------------------------------------- ; Step 2: Build the SOAP XML to be signed ; --------------------------------------- $oXml = ObjCreate("Chilkat.Xml") $oXml.Tag = "SOAP-ENV:Envelope" $oXml.AddAttribute("xmlns:SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/") $oXml.AddAttribute("xmlns:web","http://www.example.com/webservice/") $oXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",True,"xmlns:ds","http://www.w3.org/2000/09/xmldsig#") $oXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",True,"xmlns:wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd") $oXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",True,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd") $oXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",True,"xmlns:xenc","http://www.w3.org/2001/04/xmlenc#") $oXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",True,"SOAP-ENV:mustUnderstand","1") $oXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",True,"A1","") $oXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",True,"EncodingType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary") $oXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",True,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509") $oXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",True,"wsu:Id","x509cert00") $oXml.UpdateChildContent "SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",$oCert.GetEncoded() $oXml.UpdateAttrAt("SOAP-ENV:Body",True,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd") $oXml.UpdateAttrAt("SOAP-ENV:Body",True,"wsu:Id","TheBody") $oXml.UpdateChildContent "SOAP-ENV:Body|web:MyRequest|web:Parameter","MyValue" ; --------------------------------------- ; Step 3: Sign the XML ; --------------------------------------- $oGen = ObjCreate("Chilkat.XmlDSigGen") $oGen.SigLocation = "SOAP-ENV:Envelope|SOAP-ENV:Header|wsse:Security" $oGen.SigLocationMod = 0 $oGen.SigNamespacePrefix = "ds" $oGen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" $oGen.SignedInfoPrefixList = "ds wsu xenc SOAP-ENV " $oGen.IncNamespacePrefix = "c14n" $oGen.IncNamespaceUri = "http://www.w3.org/2001/10/xml-exc-c14n#" $oGen.SignedInfoCanonAlg = "EXCL_C14N" $oGen.SignedInfoDigestMethod = "sha1" ; -------- Reference 1 -------- $oGen.AddSameDocRef("TheBody","sha1","EXCL_C14N","wsu SOAP-ENV","") $oGen.SetX509Cert($oCert,True) $oGen.KeyInfoType = "Custom" ; Create the custom KeyInfo XML.. $oXmlCustomKeyInfo = ObjCreate("Chilkat.Xml") $oXmlCustomKeyInfo.Tag = "wsse:SecurityTokenReference" $oXmlCustomKeyInfo.Content = "5" $oXmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",True,"URI","#x509cert00") $oXmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",True,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509") $oXmlCustomKeyInfo.EmitXmlDecl = False $oGen.CustomKeyInfoXml = $oXmlCustomKeyInfo.GetXml() ; Load XML to be signed... $oSbXml = ObjCreate("Chilkat.StringBuilder") $oXml.EmitXmlDecl = False $oXml.GetXmlSb($oSbXml) $oGen.Behaviors = "IndentedSignature" ; Sign the XML... $bSuccess = $oGen.CreateXmlDSigSb($oSbXml) If ($bSuccess <> True) Then ConsoleWrite($oGen.LastErrorText & @CRLF) Exit EndIf ; --------------------------------------------------------- ; Step 4: Send the HTTP POST containing the Signed SOAP XML ; --------------------------------------------------------- $oHttp = ObjCreate("Chilkat.Http") $oHttp.SetRequestHeader "SOAPAction","""http://www.example.com/MyWebService""" $oHttp.SetRequestHeader "Host","www.example.com" $oHttp.SetRequestHeader "Content-Type","text/xml; charset=utf-8" Local $oResp = $oHttp.PTextSb("POST","https://example.com/MyWebService",$oSbXml,"utf-8","text/xml; charset=utf-8",False,False) If ($oHttp.LastMethodSuccess = False) Then ConsoleWrite($oHttp.LastErrorText & @CRLF) Exit EndIf ConsoleWrite($oResp.StatusCode & @CRLF) ConsoleWrite($oResp.BodyStr & @CRLF) ConsoleWrite("Finished." & @CRLF) |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.