Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(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... loXmlToSign = CreateObject('Chilkat_9_5_0.Xml') loXmlToSign.Tag = "getToken" * This is the seed obtained from palena.sii.cl getSeed loXmlToSign.UpdateChildContent("item|Semilla","033878794660") loGen = CreateObject('Chilkat_9_5_0.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) loCert = CreateObject('Chilkat_9_5_0.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... loSbXml = CreateObject('Chilkat_9_5_0.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 * ----------------------------------------------- loHttp = CreateObject('Chilkat_9_5_0.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> loXml = CreateObject('Chilkat_9_5_0.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. loSbSoapXml = CreateObject('Chilkat_9_5_0.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:" loXmlResp = CreateObject('Chilkat_9_5_0.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-2021 Chilkat Software, Inc. All Rights Reserved.