DataFlex
DataFlex
palena.sii.cl getToken SOAP Request
See more SII Chile Examples
Demonstrates how to call getToken SOAP request at palena.sii.clChilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
ToSign Handle hoXmlToSign
Handle hoGen
Variant vCert
Handle hoCert
Variant vSbXml
Handle hoSbXml
Handle hoHttp
Integer iResponseStatusCode
String sEndPoint
Handle hoXml
Handle hoSbSoapXml
Integer iNumReplaced
String sXmlStr
Variant vResp
Handle hoResp
Resp Handle hoXmlResp
String sTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Create the XML to be signed...
Get Create (RefClass(cComChilkatXml)) To hoXmlToSign
If (Not(IsComObjectCreated(hoXmlToSign))) Begin
Send CreateComObject of hoXmlToSign
End
Set ComTag Of hoXmlToSign To "getToken"
// This is the seed obtained from palena.sii.cl getSeed
Send ComUpdateChildContent To hoXmlToSign "item|Semilla" "033878794660"
Get Create (RefClass(cComChilkatXmlDSigGen)) To hoGen
If (Not(IsComObjectCreated(hoGen))) Begin
Send CreateComObject of hoGen
End
Set ComSigLocation Of hoGen To "getToken"
Set ComSigLocationMod Of hoGen To 0
Set ComSigNamespacePrefix Of hoGen To ""
Set ComSigNamespaceUri Of hoGen To "http://www.w3.org/2000/09/xmldsig#"
Set ComSignedInfoCanonAlg Of hoGen To "EXCL_C14N"
Set ComSignedInfoDigestMethod Of hoGen To "sha1"
Get ComAddSameDocRef Of hoGen "" "sha1" "" "" "" To iSuccess
// Provide a certificate + private key. (PFX password is test123)
Get Create (RefClass(cComChilkatCert)) To hoCert
If (Not(IsComObjectCreated(hoCert))) Begin
Send CreateComObject of hoCert
End
Get ComLoadPfxFile Of hoCert "qa_data/pfx/cert_test123.pfx" "test123" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoCert To sTemp1
Showln sTemp1
Procedure_Return
End
Get pvComObject of hoCert to vCert
Get ComSetX509Cert Of hoGen vCert True To iSuccess
Set ComKeyInfoType Of hoGen To "X509Data"
Set ComX509Type Of hoGen To "Certificate"
// Load XML to be signed...
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbXml
If (Not(IsComObjectCreated(hoSbXml))) Begin
Send CreateComObject of hoSbXml
End
Set ComEmitXmlDecl Of hoXmlToSign To False
Get pvComObject of hoSbXml to vSbXml
Get ComGetXmlSb Of hoXmlToSign vSbXml To iSuccess
Set ComBehaviors Of hoGen To "IndentedSignature"
// Sign the XML...
Get pvComObject of hoSbXml to vSbXml
Get ComCreateXmlDSigSb Of hoGen vSbXml To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoGen To sTemp1
Showln sTemp1
Procedure_Return
End
// -----------------------------------------------
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComUncommonOptions Of hoHttp To "AllowEmptyHeaders"
Send ComSetRequestHeader To hoHttp "SOAPAction" ""
// The endpoint for this soap service is:
Move "https://palena.sii.cl/DTEWS/GetTokenFromSeed.jws" To sEndPoint
// 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>
Get Create (RefClass(cComChilkatXml)) To hoXml
If (Not(IsComObjectCreated(hoXml))) Begin
Send CreateComObject of hoXml
End
Set ComTag Of hoXml To "soapenv:Envelope"
Get ComAddAttribute Of hoXml "xmlns:xsi" "http://www.w3.org/2001/XMLSchema-instance" To iSuccess
Get ComAddAttribute Of hoXml "xmlns:xsd" "http://www.w3.org/2001/XMLSchema" To iSuccess
Get ComAddAttribute Of hoXml "xmlns:soapenv" "http://schemas.xmlsoap.org/soap/envelope/" To iSuccess
Get ComAddAttribute Of hoXml "xmlns:def" "http://DefaultNamespace" To iSuccess
Send ComUpdateChildContent To hoXml "soapenv:Header" ""
Get ComUpdateAttrAt Of hoXml "soapenv:Body|def:getToken" True "soapenv:encodingStyle" "http://schemas.xmlsoap.org/soap/encoding/" To iSuccess
Send ComUpdateChildContent To hoXml "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.
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbSoapXml
If (Not(IsComObjectCreated(hoSbSoapXml))) Begin
Send CreateComObject of hoSbSoapXml
End
Get ComGetXml Of hoXml To sTemp1
Get ComAppend Of hoSbSoapXml sTemp1 To iSuccess
Get ComReplace Of hoSbXml "&" "&" To iNumReplaced
Get ComReplace Of hoSbXml ">" ">" To iNumReplaced
Get ComReplace Of hoSbXml "<" "<" To iNumReplaced
Get ComReplace Of hoSbXml '"' """ To iNumReplaced
Get ComGetAsString Of hoSbXml To sTemp1
Get ComReplace Of hoSbSoapXml "SIGNED_XML_GOES_HERE" sTemp1 To iNumReplaced
Get ComGetAsString Of hoSbSoapXml To sXmlStr
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoResp to vResp
Get ComHttpStr Of hoHttp "POST" sEndPoint sXmlStr "utf-8" "text/xml" vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iResponseStatusCode
Showln "Response Status Code: " iResponseStatusCode
// You may examine the exact HTTP header sent with the POST like this:
Showln "LastHeader:"
Get ComLastHeader Of hoHttp To sTemp1
Showln sTemp1
// Examine the XML returned by the web service:
Showln "XML Response:"
Get Create (RefClass(cComChilkatXml)) To hoXmlResp
If (Not(IsComObjectCreated(hoXmlResp))) Begin
Send CreateComObject of hoXmlResp
End
Get ComBodyStr Of hoResp To sTemp1
Get ComLoadXml Of hoXmlResp sTemp1 To iSuccess
Get ComGetXml Of hoXmlResp To sTemp1
Showln sTemp1
// Use this online tool to generate parsing code from response XML:
// Generate Parsing Code from XML
End_Procedure