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
(DataFlex) 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.
Use ChilkatAx-win32.pkg Procedure Test Variant vCert Handle hoCert Boolean iSuccess Handle hoXml Handle hoGen CustomKeyInfo Handle hoXmlCustomKeyInfo Variant vSbXml Handle hoSbXml Handle hoHttp Variant vResp Handle hoResp String sTemp1 Integer iTemp1 Boolean bTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // // ------------------------------------ // Step 1: Load the signing certificate // ------------------------------------ Get Create (RefClass(cComChilkatCert)) To hoCert If (Not(IsComObjectCreated(hoCert))) Begin Send CreateComObject of hoCert End Get ComLoadFromSmartcard Of hoCert "" To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoCert To sTemp1 Showln sTemp1 Procedure_Return End // --------------------------------------- // Step 2: Build the SOAP XML to be signed // --------------------------------------- Get Create (RefClass(cComChilkatXml)) To hoXml If (Not(IsComObjectCreated(hoXml))) Begin Send CreateComObject of hoXml End Set ComTag Of hoXml To "SOAP-ENV:Envelope" Get ComAddAttribute Of hoXml "xmlns:SOAP-ENV" "http://schemas.xmlsoap.org/soap/envelope/" To iSuccess Get ComAddAttribute Of hoXml "xmlns:web" "http://www.example.com/webservice/" To iSuccess Get ComUpdateAttrAt Of hoXml "SOAP-ENV:Header|wsse:Security" True "xmlns:ds" "http://www.w3.org/2000/09/xmldsig#" To iSuccess Get ComUpdateAttrAt Of hoXml "SOAP-ENV:Header|wsse:Security" True "xmlns:wsse" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" To iSuccess Get ComUpdateAttrAt Of hoXml "SOAP-ENV:Header|wsse:Security" True "xmlns:wsu" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" To iSuccess Get ComUpdateAttrAt Of hoXml "SOAP-ENV:Header|wsse:Security" True "xmlns:xenc" "http://www.w3.org/2001/04/xmlenc#" To iSuccess Get ComUpdateAttrAt Of hoXml "SOAP-ENV:Header|wsse:Security" True "SOAP-ENV:mustUnderstand" "1" To iSuccess Get ComUpdateAttrAt Of hoXml "SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken" True "A1" "" To iSuccess Get ComUpdateAttrAt Of hoXml "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" To iSuccess Get ComUpdateAttrAt Of hoXml "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" To iSuccess Get ComUpdateAttrAt Of hoXml "SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken" True "wsu:Id" "x509cert00" To iSuccess Get ComGetEncoded Of hoCert To sTemp1 Send ComUpdateChildContent To hoXml "SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken" sTemp1 Get ComUpdateAttrAt Of hoXml "SOAP-ENV:Body" True "xmlns:wsu" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" To iSuccess Get ComUpdateAttrAt Of hoXml "SOAP-ENV:Body" True "wsu:Id" "TheBody" To iSuccess Send ComUpdateChildContent To hoXml "SOAP-ENV:Body|web:MyRequest|web:Parameter" "MyValue" // --------------------------------------- // Step 3: Sign the XML // --------------------------------------- Get Create (RefClass(cComChilkatXmlDSigGen)) To hoGen If (Not(IsComObjectCreated(hoGen))) Begin Send CreateComObject of hoGen End Set ComSigLocation Of hoGen To "SOAP-ENV:Envelope|SOAP-ENV:Header|wsse:Security" Set ComSigLocationMod Of hoGen To 0 Set ComSigNamespacePrefix Of hoGen To "ds" Set ComSigNamespaceUri Of hoGen To "http://www.w3.org/2000/09/xmldsig#" Set ComSignedInfoPrefixList Of hoGen To "ds wsu xenc SOAP-ENV " Set ComIncNamespacePrefix Of hoGen To "c14n" Set ComIncNamespaceUri Of hoGen To "http://www.w3.org/2001/10/xml-exc-c14n#" Set ComSignedInfoCanonAlg Of hoGen To "EXCL_C14N" Set ComSignedInfoDigestMethod Of hoGen To "sha1" // -------- Reference 1 -------- Get ComAddSameDocRef Of hoGen "TheBody" "sha1" "EXCL_C14N" "wsu SOAP-ENV" "" To iSuccess Get pvComObject of hoCert to vCert Get ComSetX509Cert Of hoGen vCert True To iSuccess Set ComKeyInfoType Of hoGen To "Custom" // Create the custom KeyInfo XML.. Get Create (RefClass(cComChilkatXml)) To hoXmlCustomKeyInfo If (Not(IsComObjectCreated(hoXmlCustomKeyInfo))) Begin Send CreateComObject of hoXmlCustomKeyInfo End Set ComTag Of hoXmlCustomKeyInfo To "wsse:SecurityTokenReference" Set ComContent Of hoXmlCustomKeyInfo To "5" Get ComUpdateAttrAt Of hoXmlCustomKeyInfo "wsse:Reference" True "URI" "#x509cert00" To iSuccess Get ComUpdateAttrAt Of hoXmlCustomKeyInfo "wsse:Reference" True "ValueType" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509" To iSuccess Set ComEmitXmlDecl Of hoXmlCustomKeyInfo To False Get ComGetXml Of hoXmlCustomKeyInfo To sTemp1 Set ComCustomKeyInfoXml Of hoGen To sTemp1 // Load XML to be signed... Get Create (RefClass(cComChilkatStringBuilder)) To hoSbXml If (Not(IsComObjectCreated(hoSbXml))) Begin Send CreateComObject of hoSbXml End Set ComEmitXmlDecl Of hoXml To False Get pvComObject of hoSbXml to vSbXml Get ComGetXmlSb Of hoXml vSbXml To iSuccess Set ComBehaviors Of hoGen To "IndentedSignature" // Sign the XML... Get pvComObject of hoSbXml to vSbXml Get ComCreateXmlDSigSb Of hoGen vSbXml To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoGen To sTemp1 Showln sTemp1 Procedure_Return End // --------------------------------------------------------- // Step 4: Send the HTTP POST containing the Signed SOAP XML // --------------------------------------------------------- Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Send ComSetRequestHeader To hoHttp "SOAPAction" '"http://www.example.com/MyWebService"' Send ComSetRequestHeader To hoHttp "Host" "www.example.com" Send ComSetRequestHeader To hoHttp "Content-Type" "text/xml; charset=utf-8" Get pvComObject of hoSbXml to vSbXml Get ComPTextSb Of hoHttp "POST" "https://example.com/MyWebService" vSbXml "utf-8" "text/xml; charset=utf-8" False False To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get ComStatusCode Of hoResp To iTemp1 Showln iTemp1 Get ComBodyStr Of hoResp To sTemp1 Showln sTemp1 Send Destroy of hoResp Showln "Finished." End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.