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
(Visual FoxPro) 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.
LOCAL loCert LOCAL lnSuccess LOCAL loXml LOCAL loGen LOCAL loXmlCustomKeyInfo LOCAL loSbXml LOCAL loHttp LOCAL loResp * This example assumes the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * * ------------------------------------ * Step 1: Load the signing certificate * ------------------------------------ * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Cert') loCert = CreateObject('Chilkat.Cert') lnSuccess = loCert.LoadFromSmartcard("") IF (lnSuccess = 0) THEN ? loCert.LastErrorText RELEASE loCert CANCEL ENDIF * --------------------------------------- * Step 2: Build the SOAP XML to be signed * --------------------------------------- * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml') loXml = CreateObject('Chilkat.Xml') loXml.Tag = "SOAP-ENV:Envelope" loXml.AddAttribute("xmlns:SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/") loXml.AddAttribute("xmlns:web","http://www.example.com/webservice/") loXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:ds","http://www.w3.org/2000/09/xmldsig#") loXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd") loXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd") loXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:xenc","http://www.w3.org/2001/04/xmlenc#") loXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"SOAP-ENV:mustUnderstand","1") loXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"A1","") loXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"EncodingType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary") loXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509") loXml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"wsu:Id","x509cert00") loXml.UpdateChildContent("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",loCert.GetEncoded()) loXml.UpdateAttrAt("SOAP-ENV:Body",1,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd") loXml.UpdateAttrAt("SOAP-ENV:Body",1,"wsu:Id","TheBody") loXml.UpdateChildContent("SOAP-ENV:Body|web:MyRequest|web:Parameter","MyValue") * --------------------------------------- * Step 3: Sign the XML * --------------------------------------- * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.XmlDSigGen') loGen = CreateObject('Chilkat.XmlDSigGen') loGen.SigLocation = "SOAP-ENV:Envelope|SOAP-ENV:Header|wsse:Security" loGen.SigLocationMod = 0 loGen.SigNamespacePrefix = "ds" loGen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" loGen.SignedInfoPrefixList = "ds wsu xenc SOAP-ENV " loGen.IncNamespacePrefix = "c14n" loGen.IncNamespaceUri = "http://www.w3.org/2001/10/xml-exc-c14n#" loGen.SignedInfoCanonAlg = "EXCL_C14N" loGen.SignedInfoDigestMethod = "sha1" * -------- Reference 1 -------- loGen.AddSameDocRef("TheBody","sha1","EXCL_C14N","wsu SOAP-ENV","") loGen.SetX509Cert(loCert,1) loGen.KeyInfoType = "Custom" * Create the custom KeyInfo XML.. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml') loXmlCustomKeyInfo = CreateObject('Chilkat.Xml') loXmlCustomKeyInfo.Tag = "wsse:SecurityTokenReference" loXmlCustomKeyInfo.Content = "5" loXmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"URI","#x509cert00") loXmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509") loXmlCustomKeyInfo.EmitXmlDecl = 0 loGen.CustomKeyInfoXml = loXmlCustomKeyInfo.GetXml() * Load XML to be signed... * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbXml = CreateObject('Chilkat.StringBuilder') loXml.EmitXmlDecl = 0 loXml.GetXmlSb(loSbXml) loGen.Behaviors = "IndentedSignature" * Sign the XML... lnSuccess = loGen.CreateXmlDSigSb(loSbXml) IF (lnSuccess <> 1) THEN ? loGen.LastErrorText RELEASE loCert RELEASE loXml RELEASE loGen RELEASE loXmlCustomKeyInfo RELEASE loSbXml CANCEL ENDIF * --------------------------------------------------------- * Step 4: Send the HTTP POST containing the Signed SOAP XML * --------------------------------------------------------- * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http') loHttp = CreateObject('Chilkat.Http') loHttp.SetRequestHeader("SOAPAction",'"http://www.example.com/MyWebService"') loHttp.SetRequestHeader("Host","www.example.com") loHttp.SetRequestHeader("Content-Type","text/xml; charset=utf-8") loResp = loHttp.PTextSb("POST","https://example.com/MyWebService",loSbXml,"utf-8","text/xml; charset=utf-8",0,0) IF (loHttp.LastMethodSuccess = 0) THEN ? loHttp.LastErrorText RELEASE loCert RELEASE loXml RELEASE loGen RELEASE loXmlCustomKeyInfo RELEASE loSbXml RELEASE loHttp CANCEL ENDIF ? STR(loResp.StatusCode) ? loResp.BodyStr RELEASE loResp ? "Finished." RELEASE loCert RELEASE loXml RELEASE loGen RELEASE loXmlCustomKeyInfo RELEASE loSbXml RELEASE loHttp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.