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
(PowerBuilder) 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.
integer li_rc oleobject loo_Cert integer li_Success oleobject loo_Xml oleobject loo_Gen oleobject loo_XmlCustomKeyInfo oleobject loo_SbXml oleobject loo_Http oleobject loo_Resp // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // // ------------------------------------ // Step 1: Load the signing certificate // ------------------------------------ loo_Cert = create oleobject // Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert") if li_rc < 0 then destroy loo_Cert MessageBox("Error","Connecting to COM object failed") return end if li_Success = loo_Cert.LoadFromSmartcard("") if li_Success = 0 then Write-Debug loo_Cert.LastErrorText destroy loo_Cert return end if // --------------------------------------- // Step 2: Build the SOAP XML to be signed // --------------------------------------- loo_Xml = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml") loo_Xml.Tag = "SOAP-ENV:Envelope" loo_Xml.AddAttribute("xmlns:SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/") loo_Xml.AddAttribute("xmlns:web","http://www.example.com/webservice/") loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:ds","http://www.w3.org/2000/09/xmldsig#") loo_Xml.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") loo_Xml.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") loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:xenc","http://www.w3.org/2001/04/xmlenc#") loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"SOAP-ENV:mustUnderstand","1") loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"A1","") loo_Xml.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") loo_Xml.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") loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"wsu:Id","x509cert00") loo_Xml.UpdateChildContent("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",loo_Cert.GetEncoded()) loo_Xml.UpdateAttrAt("SOAP-ENV:Body",1,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd") loo_Xml.UpdateAttrAt("SOAP-ENV:Body",1,"wsu:Id","TheBody") loo_Xml.UpdateChildContent("SOAP-ENV:Body|web:MyRequest|web:Parameter","MyValue") // --------------------------------------- // Step 3: Sign the XML // --------------------------------------- loo_Gen = create oleobject // Use "Chilkat_9_5_0.XmlDSigGen" for versions of Chilkat < 10.0.0 li_rc = loo_Gen.ConnectToNewObject("Chilkat.XmlDSigGen") loo_Gen.SigLocation = "SOAP-ENV:Envelope|SOAP-ENV:Header|wsse:Security" loo_Gen.SigLocationMod = 0 loo_Gen.SigNamespacePrefix = "ds" loo_Gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" loo_Gen.SignedInfoPrefixList = "ds wsu xenc SOAP-ENV " loo_Gen.IncNamespacePrefix = "c14n" loo_Gen.IncNamespaceUri = "http://www.w3.org/2001/10/xml-exc-c14n#" loo_Gen.SignedInfoCanonAlg = "EXCL_C14N" loo_Gen.SignedInfoDigestMethod = "sha1" // -------- Reference 1 -------- loo_Gen.AddSameDocRef("TheBody","sha1","EXCL_C14N","wsu SOAP-ENV","") loo_Gen.SetX509Cert(loo_Cert,1) loo_Gen.KeyInfoType = "Custom" // Create the custom KeyInfo XML.. loo_XmlCustomKeyInfo = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_XmlCustomKeyInfo.ConnectToNewObject("Chilkat.Xml") loo_XmlCustomKeyInfo.Tag = "wsse:SecurityTokenReference" loo_XmlCustomKeyInfo.Content = "5" loo_XmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"URI","#x509cert00") loo_XmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509") loo_XmlCustomKeyInfo.EmitXmlDecl = 0 loo_Gen.CustomKeyInfoXml = loo_XmlCustomKeyInfo.GetXml() // Load XML to be signed... loo_SbXml = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder") loo_Xml.EmitXmlDecl = 0 loo_Xml.GetXmlSb(loo_SbXml) loo_Gen.Behaviors = "IndentedSignature" // Sign the XML... li_Success = loo_Gen.CreateXmlDSigSb(loo_SbXml) if li_Success <> 1 then Write-Debug loo_Gen.LastErrorText destroy loo_Cert destroy loo_Xml destroy loo_Gen destroy loo_XmlCustomKeyInfo destroy loo_SbXml return end if // --------------------------------------------------------- // Step 4: Send the HTTP POST containing the Signed SOAP XML // --------------------------------------------------------- loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") loo_Http.SetRequestHeader("SOAPAction","~"http://www.example.com/MyWebService~"") loo_Http.SetRequestHeader("Host","www.example.com") loo_Http.SetRequestHeader("Content-Type","text/xml; charset=utf-8") loo_Resp = loo_Http.PTextSb("POST","https://example.com/MyWebService",loo_SbXml,"utf-8","text/xml; charset=utf-8",0,0) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Cert destroy loo_Xml destroy loo_Gen destroy loo_XmlCustomKeyInfo destroy loo_SbXml destroy loo_Http return end if Write-Debug string(loo_Resp.StatusCode) Write-Debug loo_Resp.BodyStr destroy loo_Resp Write-Debug "Finished." destroy loo_Cert destroy loo_Xml destroy loo_Gen destroy loo_XmlCustomKeyInfo destroy loo_SbXml destroy loo_Http |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.