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
(Tcl) palena.sii.cl getToken SOAP RequestDemonstrates how to call getToken SOAP request at palena.sii.cl
load ./chilkat.dll # This example requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. # Create the XML to be signed... set xmlToSign [new_CkXml] CkXml_put_Tag $xmlToSign "getToken" # This is the seed obtained from palena.sii.cl getSeed CkXml_UpdateChildContent $xmlToSign "item|Semilla" "033878794660" set gen [new_CkXmlDSigGen] CkXmlDSigGen_put_SigLocation $gen "getToken" CkXmlDSigGen_put_SigLocationMod $gen 0 CkXmlDSigGen_put_SigNamespacePrefix $gen "" CkXmlDSigGen_put_SigNamespaceUri $gen "http://www.w3.org/2000/09/xmldsig#" CkXmlDSigGen_put_SignedInfoCanonAlg $gen "EXCL_C14N" CkXmlDSigGen_put_SignedInfoDigestMethod $gen "sha1" CkXmlDSigGen_AddSameDocRef $gen "" "sha1" "" "" "" # Provide a certificate + private key. (PFX password is test123) set cert [new_CkCert] set success [CkCert_LoadPfxFile $cert "qa_data/pfx/cert_test123.pfx" "test123"] if {$success != 1} then { puts [CkCert_lastErrorText $cert] delete_CkXml $xmlToSign delete_CkXmlDSigGen $gen delete_CkCert $cert exit } CkXmlDSigGen_SetX509Cert $gen $cert 1 CkXmlDSigGen_put_KeyInfoType $gen "X509Data" CkXmlDSigGen_put_X509Type $gen "Certificate" # Load XML to be signed... set sbXml [new_CkStringBuilder] CkXml_put_EmitXmlDecl $xmlToSign 0 CkXml_GetXmlSb $xmlToSign $sbXml CkXmlDSigGen_put_Behaviors $gen "IndentedSignature" # Sign the XML... set success [CkXmlDSigGen_CreateXmlDSigSb $gen $sbXml] if {$success != 1} then { puts [CkXmlDSigGen_lastErrorText $gen] delete_CkXml $xmlToSign delete_CkXmlDSigGen $gen delete_CkCert $cert delete_CkStringBuilder $sbXml exit } # ----------------------------------------------- set http [new_CkHttp] CkHttp_put_UncommonOptions $http "AllowEmptyHeaders" CkHttp_SetRequestHeader $http "SOAPAction" "" CkHttp_SetRequestHeader $http "Content-Type" "text/xml; charset=utf-8" # The endpoint for this soap service is: set 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> set xml [new_CkXml] CkXml_put_Tag $xml "soapenv:Envelope" CkXml_AddAttribute $xml "xmlns:xsi" "http://www.w3.org/2001/XMLSchema-instance" CkXml_AddAttribute $xml "xmlns:xsd" "http://www.w3.org/2001/XMLSchema" CkXml_AddAttribute $xml "xmlns:soapenv" "http://schemas.xmlsoap.org/soap/envelope/" CkXml_AddAttribute $xml "xmlns:def" "http://DefaultNamespace" CkXml_UpdateChildContent $xml "soapenv:Header" "" CkXml_UpdateAttrAt $xml "soapenv:Body|def:getToken" 1 "soapenv:encodingStyle" "http://schemas.xmlsoap.org/soap/encoding/" CkXml_UpdateChildContent $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. set sbSoapXml [new_CkStringBuilder] CkStringBuilder_Append $sbSoapXml [CkXml_getXml $xml] set numReplaced [CkStringBuilder_Replace $sbXml "&" "&"] set numReplaced [CkStringBuilder_Replace $sbXml ">" ">"] set numReplaced [CkStringBuilder_Replace $sbXml "<" "<"] set numReplaced [CkStringBuilder_Replace $sbXml "\"" """] set numReplaced [CkStringBuilder_Replace $sbSoapXml "SIGNED_XML_GOES_HERE" [CkStringBuilder_getAsString $sbXml]] # resp is a CkHttpResponse set resp [CkHttp_PostXml $http $endPoint [CkStringBuilder_getAsString $sbSoapXml] "utf-8"] if {[CkHttp_get_LastMethodSuccess $http] != 1} then { puts [CkHttp_lastErrorText $http] puts "LastHeader:" puts [CkHttp_lastHeader $http] delete_CkXml $xmlToSign delete_CkXmlDSigGen $gen delete_CkCert $cert delete_CkStringBuilder $sbXml delete_CkHttp $http delete_CkXml $xml delete_CkStringBuilder $sbSoapXml exit } set responseStatusCode [CkHttpResponse_get_StatusCode $resp] puts "Response Status Code: $responseStatusCode" # You may examine the exact HTTP header sent with the POST like this: puts "LastHeader:" puts [CkHttp_lastHeader $http] # Examine the XML returned by the web service: puts "XML Response:" set xmlResp [new_CkXml] CkXml_LoadXml $xmlResp [CkHttpResponse_bodyStr $resp] puts [CkXml_getXml $xmlResp] # Use this online tool to generate parsing code from response XML: # Generate Parsing Code from XML delete_CkHttpResponse $resp delete_CkXml $xmlToSign delete_CkXmlDSigGen $gen delete_CkCert $cert delete_CkStringBuilder $sbXml delete_CkHttp $http delete_CkXml $xml delete_CkStringBuilder $sbSoapXml delete_CkXml $xmlResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.