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) palena.sii.cl getToken SOAP RequestDemonstrates how to call getToken SOAP request at palena.sii.cl
integer li_rc integer li_Success oleobject loo_XmlToSign oleobject loo_Gen oleobject loo_Cert oleobject loo_SbXml oleobject loo_Http integer li_ResponseStatusCode string ls_EndPoint oleobject loo_Xml oleobject loo_SbSoapXml integer li_NumReplaced oleobject loo_Resp oleobject loo_XmlResp // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Create the XML to be signed... loo_XmlToSign = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_XmlToSign.ConnectToNewObject("Chilkat.Xml") if li_rc < 0 then destroy loo_XmlToSign MessageBox("Error","Connecting to COM object failed") return end if loo_XmlToSign.Tag = "getToken" // This is the seed obtained from palena.sii.cl getSeed loo_XmlToSign.UpdateChildContent("item|Semilla","033878794660") 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 = "getToken" loo_Gen.SigLocationMod = 0 loo_Gen.SigNamespacePrefix = "" loo_Gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" loo_Gen.SignedInfoCanonAlg = "EXCL_C14N" loo_Gen.SignedInfoDigestMethod = "sha1" loo_Gen.AddSameDocRef("","sha1","","","") // Provide a certificate + private key. (PFX password is test123) loo_Cert = create oleobject // Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert") li_Success = loo_Cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123") if li_Success <> 1 then Write-Debug loo_Cert.LastErrorText destroy loo_XmlToSign destroy loo_Gen destroy loo_Cert return end if loo_Gen.SetX509Cert(loo_Cert,1) loo_Gen.KeyInfoType = "X509Data" loo_Gen.X509Type = "Certificate" // 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_XmlToSign.EmitXmlDecl = 0 loo_XmlToSign.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_XmlToSign destroy loo_Gen destroy loo_Cert destroy loo_SbXml return end if // ----------------------------------------------- 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.UncommonOptions = "AllowEmptyHeaders" loo_Http.SetRequestHeader("SOAPAction","") loo_Http.SetRequestHeader("Content-Type","text/xml; charset=utf-8") // The endpoint for this soap service is: ls_EndPoint = "https://palena.sii.cl/DTEWS/GetTokenFromSeed.jws" // Send the following SOAP XML // <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:def="http://DefaultNamespace"> // <soapenv:Header/> // <soapenv:Body> // <def:getToken soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> // <pszXml>SIGNED_XML_GOES_HERE</pszXml> // </def:getToken> // </soapenv:Body> // </soapenv:Envelope> 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 = "soapenv:Envelope" loo_Xml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") loo_Xml.AddAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema") loo_Xml.AddAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/") loo_Xml.AddAttribute("xmlns:def","http://DefaultNamespace") loo_Xml.UpdateChildContent("soapenv:Header","") loo_Xml.UpdateAttrAt("soapenv:Body|def:getToken",1,"soapenv:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/") loo_Xml.UpdateChildContent("soapenv:Body|def:getToken|pszXml","SIGNED_XML_GOES_HERE") // We must replace the "SIGNED_XML_GOES_HERE" with the exact contents of the signed XML to ensure the signed XML is not modified in any way. loo_SbSoapXml = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbSoapXml.ConnectToNewObject("Chilkat.StringBuilder") loo_SbSoapXml.Append(loo_Xml.GetXml()) li_NumReplaced = loo_SbXml.Replace("&","&") li_NumReplaced = loo_SbXml.Replace(">",">") li_NumReplaced = loo_SbXml.Replace("<","<") li_NumReplaced = loo_SbXml.Replace("~"",""") li_NumReplaced = loo_SbSoapXml.Replace("SIGNED_XML_GOES_HERE",loo_SbXml.GetAsString()) loo_Resp = loo_Http.PostXml(ls_EndPoint,loo_SbSoapXml.GetAsString(),"utf-8") if loo_Http.LastMethodSuccess <> 1 then Write-Debug loo_Http.LastErrorText Write-Debug "LastHeader:" Write-Debug loo_Http.LastHeader destroy loo_XmlToSign destroy loo_Gen destroy loo_Cert destroy loo_SbXml destroy loo_Http destroy loo_Xml destroy loo_SbSoapXml return end if li_ResponseStatusCode = loo_Resp.StatusCode Write-Debug "Response Status Code: " + string(li_ResponseStatusCode) // You may examine the exact HTTP header sent with the POST like this: Write-Debug "LastHeader:" Write-Debug loo_Http.LastHeader // Examine the XML returned by the web service: Write-Debug "XML Response:" loo_XmlResp = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_XmlResp.ConnectToNewObject("Chilkat.Xml") loo_XmlResp.LoadXml(loo_Resp.BodyStr) Write-Debug loo_XmlResp.GetXml() // Use this online tool to generate parsing code from response XML: // Generate Parsing Code from XML destroy loo_Resp destroy loo_XmlToSign destroy loo_Gen destroy loo_Cert destroy loo_SbXml destroy loo_Http destroy loo_Xml destroy loo_SbSoapXml destroy loo_XmlResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.