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) palena.sii.cl getToken SOAP RequestDemonstrates how to call getToken SOAP request at palena.sii.cl
LOCAL lnSuccess LOCAL loXmlToSign LOCAL loGen LOCAL loCert LOCAL loSbXml LOCAL loHttp LOCAL lnResponseStatusCode LOCAL lcEndPoint LOCAL loXml LOCAL loSbSoapXml LOCAL lnNumReplaced LOCAL loResp LOCAL loXmlResp * This example requires the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * Create the XML to be signed... * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml') loXmlToSign = CreateObject('Chilkat.Xml') loXmlToSign.Tag = "getToken" * This is the seed obtained from palena.sii.cl getSeed loXmlToSign.UpdateChildContent("item|Semilla","033878794660") * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.XmlDSigGen') loGen = CreateObject('Chilkat.XmlDSigGen') loGen.SigLocation = "getToken" loGen.SigLocationMod = 0 loGen.SigNamespacePrefix = "" loGen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" loGen.SignedInfoCanonAlg = "EXCL_C14N" loGen.SignedInfoDigestMethod = "sha1" loGen.AddSameDocRef("","sha1","","","") * Provide a certificate + private key. (PFX password is test123) * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Cert') loCert = CreateObject('Chilkat.Cert') lnSuccess = loCert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123") IF (lnSuccess <> 1) THEN ? loCert.LastErrorText RELEASE loXmlToSign RELEASE loGen RELEASE loCert CANCEL ENDIF loGen.SetX509Cert(loCert,1) loGen.KeyInfoType = "X509Data" loGen.X509Type = "Certificate" * Load XML to be signed... * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbXml = CreateObject('Chilkat.StringBuilder') loXmlToSign.EmitXmlDecl = 0 loXmlToSign.GetXmlSb(loSbXml) loGen.Behaviors = "IndentedSignature" * Sign the XML... lnSuccess = loGen.CreateXmlDSigSb(loSbXml) IF (lnSuccess <> 1) THEN ? loGen.LastErrorText RELEASE loXmlToSign RELEASE loGen RELEASE loCert RELEASE loSbXml CANCEL ENDIF * ----------------------------------------------- * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http') loHttp = CreateObject('Chilkat.Http') loHttp.UncommonOptions = "AllowEmptyHeaders" loHttp.SetRequestHeader("SOAPAction","") loHttp.SetRequestHeader("Content-Type","text/xml; charset=utf-8") * The endpoint for this soap service is: lcEndPoint = "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> * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml') loXml = CreateObject('Chilkat.Xml') loXml.Tag = "soapenv:Envelope" loXml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") loXml.AddAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema") loXml.AddAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/") loXml.AddAttribute("xmlns:def","http://DefaultNamespace") loXml.UpdateChildContent("soapenv:Header","") loXml.UpdateAttrAt("soapenv:Body|def:getToken",1,"soapenv:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/") loXml.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. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbSoapXml = CreateObject('Chilkat.StringBuilder') loSbSoapXml.Append(loXml.GetXml()) lnNumReplaced = loSbXml.Replace("&","&") lnNumReplaced = loSbXml.Replace(">",">") lnNumReplaced = loSbXml.Replace("<","<") lnNumReplaced = loSbXml.Replace('"',""") lnNumReplaced = loSbSoapXml.Replace("SIGNED_XML_GOES_HERE",loSbXml.GetAsString()) loResp = loHttp.PostXml(lcEndPoint,loSbSoapXml.GetAsString(),"utf-8") IF (loHttp.LastMethodSuccess <> 1) THEN ? loHttp.LastErrorText ? "LastHeader:" ? loHttp.LastHeader RELEASE loXmlToSign RELEASE loGen RELEASE loCert RELEASE loSbXml RELEASE loHttp RELEASE loXml RELEASE loSbSoapXml CANCEL ENDIF lnResponseStatusCode = loResp.StatusCode ? "Response Status Code: " + STR(lnResponseStatusCode) * You may examine the exact HTTP header sent with the POST like this: ? "LastHeader:" ? loHttp.LastHeader * Examine the XML returned by the web service: ? "XML Response:" * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml') loXmlResp = CreateObject('Chilkat.Xml') loXmlResp.LoadXml(loResp.BodyStr) ? loXmlResp.GetXml() * Use this online tool to generate parsing code from response XML: * Generate Parsing Code from XML RELEASE loResp RELEASE loXmlToSign RELEASE loGen RELEASE loCert RELEASE loSbXml RELEASE loHttp RELEASE loXml RELEASE loSbSoapXml RELEASE loXmlResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.