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
(PureBasic) palena.sii.cl getToken SOAP RequestDemonstrates how to call getToken SOAP request at palena.sii.cl
IncludeFile "CkXml.pb" IncludeFile "CkHttp.pb" IncludeFile "CkXmlDSigGen.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkHttpResponse.pb" IncludeFile "CkCert.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. success.i ; Create the XML to be signed... xmlToSign.i = CkXml::ckCreate() If xmlToSign.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::setCkTag(xmlToSign, "getToken") ; This is the seed obtained from palena.sii.cl getSeed CkXml::ckUpdateChildContent(xmlToSign,"item|Semilla","033878794660") gen.i = CkXmlDSigGen::ckCreate() If gen.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXmlDSigGen::setCkSigLocation(gen, "getToken") CkXmlDSigGen::setCkSigLocationMod(gen, 0) CkXmlDSigGen::setCkSigNamespacePrefix(gen, "") CkXmlDSigGen::setCkSigNamespaceUri(gen, "http://www.w3.org/2000/09/xmldsig#") CkXmlDSigGen::setCkSignedInfoCanonAlg(gen, "EXCL_C14N") CkXmlDSigGen::setCkSignedInfoDigestMethod(gen, "sha1") CkXmlDSigGen::ckAddSameDocRef(gen,"","sha1","","","") ; Provide a certificate + private key. (PFX password is test123) cert.i = CkCert::ckCreate() If cert.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkCert::ckLoadPfxFile(cert,"qa_data/pfx/cert_test123.pfx","test123") If success <> 1 Debug CkCert::ckLastErrorText(cert) CkXml::ckDispose(xmlToSign) CkXmlDSigGen::ckDispose(gen) CkCert::ckDispose(cert) ProcedureReturn EndIf CkXmlDSigGen::ckSetX509Cert(gen,cert,1) CkXmlDSigGen::setCkKeyInfoType(gen, "X509Data") CkXmlDSigGen::setCkX509Type(gen, "Certificate") ; Load XML to be signed... sbXml.i = CkStringBuilder::ckCreate() If sbXml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::setCkEmitXmlDecl(xmlToSign, 0) CkXml::ckGetXmlSb(xmlToSign,sbXml) CkXmlDSigGen::setCkBehaviors(gen, "IndentedSignature") ; Sign the XML... success = CkXmlDSigGen::ckCreateXmlDSigSb(gen,sbXml) If success <> 1 Debug CkXmlDSigGen::ckLastErrorText(gen) CkXml::ckDispose(xmlToSign) CkXmlDSigGen::ckDispose(gen) CkCert::ckDispose(cert) CkStringBuilder::ckDispose(sbXml) ProcedureReturn EndIf ; ----------------------------------------------- http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf responseStatusCode.i CkHttp::setCkUncommonOptions(http, "AllowEmptyHeaders") CkHttp::ckSetRequestHeader(http,"SOAPAction","") CkHttp::ckSetRequestHeader(http,"Content-Type","text/xml; charset=utf-8") ; The endpoint for this soap service is: endPoint.s = "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> xml.i = CkXml::ckCreate() If xml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::setCkTag(xml, "soapenv:Envelope") CkXml::ckAddAttribute(xml,"xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") CkXml::ckAddAttribute(xml,"xmlns:xsd","http://www.w3.org/2001/XMLSchema") CkXml::ckAddAttribute(xml,"xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/") CkXml::ckAddAttribute(xml,"xmlns:def","http://DefaultNamespace") CkXml::ckUpdateChildContent(xml,"soapenv:Header","") CkXml::ckUpdateAttrAt(xml,"soapenv:Body|def:getToken",1,"soapenv:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/") CkXml::ckUpdateChildContent(xml,"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. sbSoapXml.i = CkStringBuilder::ckCreate() If sbSoapXml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbSoapXml,CkXml::ckGetXml(xml)) numReplaced.i = CkStringBuilder::ckReplace(sbXml,"&","&") numReplaced = CkStringBuilder::ckReplace(sbXml,">",">") numReplaced = CkStringBuilder::ckReplace(sbXml,"<","<") numReplaced = CkStringBuilder::ckReplace(sbXml,Chr(34),""") numReplaced = CkStringBuilder::ckReplace(sbSoapXml,"SIGNED_XML_GOES_HERE",CkStringBuilder::ckGetAsString(sbXml)) resp.i = CkHttp::ckPostXml(http,endPoint,CkStringBuilder::ckGetAsString(sbSoapXml),"utf-8") If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) Debug "LastHeader:" Debug CkHttp::ckLastHeader(http) CkXml::ckDispose(xmlToSign) CkXmlDSigGen::ckDispose(gen) CkCert::ckDispose(cert) CkStringBuilder::ckDispose(sbXml) CkHttp::ckDispose(http) CkXml::ckDispose(xml) CkStringBuilder::ckDispose(sbSoapXml) ProcedureReturn EndIf responseStatusCode = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code: " + Str(responseStatusCode) ; You may examine the exact HTTP header sent with the POST like this: Debug "LastHeader:" Debug CkHttp::ckLastHeader(http) ; Examine the XML returned by the web service: Debug "XML Response:" xmlResp.i = CkXml::ckCreate() If xmlResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::ckLoadXml(xmlResp,CkHttpResponse::ckBodyStr(resp)) Debug CkXml::ckGetXml(xmlResp) ; Use this online tool to generate parsing code from response XML: ; Generate Parsing Code from XML CkHttpResponse::ckDispose(resp) CkXml::ckDispose(xmlToSign) CkXmlDSigGen::ckDispose(gen) CkCert::ckDispose(cert) CkStringBuilder::ckDispose(sbXml) CkHttp::ckDispose(http) CkXml::ckDispose(xml) CkStringBuilder::ckDispose(sbSoapXml) CkXml::ckDispose(xmlResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.