PowerBuilder
PowerBuilder
palena.sii.cl getToken SOAP Request
See more SII Chile Examples
Demonstrates how to call getToken SOAP request at palena.sii.clChilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_XmlToSign
oleobject loo_Gen
oleobject loo_Cert
oleobject loo_SbXml
oleobject loo_Http
integer li_ResponseStatusCode
string ls_EndPoint
oleobject loo_Xml
oleobject loo_SbSoapXml
integer li_NumReplaced
string ls_XmlStr
oleobject loo_Resp
oleobject loo_XmlResp
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Create the XML to be signed...
loo_XmlToSign = create oleobject
li_rc = loo_XmlToSign.ConnectToNewObject("Chilkat.Xml")
if li_rc < 0 then
destroy loo_XmlToSign
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_XmlToSign.Tag = "getToken"
// This is the seed obtained from palena.sii.cl getSeed
loo_XmlToSign.UpdateChildContent("item|Semilla","033878794660")
loo_Gen = create oleobject
li_rc = loo_Gen.ConnectToNewObject("Chilkat.XmlDSigGen")
loo_Gen.SigLocation = "getToken"
loo_Gen.SigLocationMod = 0
loo_Gen.SigNamespacePrefix = ""
loo_Gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#"
loo_Gen.SignedInfoCanonAlg = "EXCL_C14N"
loo_Gen.SignedInfoDigestMethod = "sha1"
loo_Gen.AddSameDocRef("","sha1","","","")
// Provide a certificate + private key. (PFX password is test123)
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_Cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_XmlToSign
destroy loo_Gen
destroy loo_Cert
return
end if
loo_Gen.SetX509Cert(loo_Cert,1)
loo_Gen.KeyInfoType = "X509Data"
loo_Gen.X509Type = "Certificate"
// Load XML to be signed...
loo_SbXml = create oleobject
li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder")
loo_XmlToSign.EmitXmlDecl = 0
loo_XmlToSign.GetXmlSb(loo_SbXml)
loo_Gen.Behaviors = "IndentedSignature"
// Sign the XML...
li_Success = loo_Gen.CreateXmlDSigSb(loo_SbXml)
if li_Success = 0 then
Write-Debug loo_Gen.LastErrorText
destroy loo_XmlToSign
destroy loo_Gen
destroy loo_Cert
destroy loo_SbXml
return
end if
// -----------------------------------------------
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
loo_Http.UncommonOptions = "AllowEmptyHeaders"
loo_Http.SetRequestHeader("SOAPAction","")
// The endpoint for this soap service is:
ls_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>
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
loo_Xml.Tag = "soapenv:Envelope"
loo_Xml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
loo_Xml.AddAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema")
loo_Xml.AddAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/")
loo_Xml.AddAttribute("xmlns:def","http://DefaultNamespace")
loo_Xml.UpdateChildContent("soapenv:Header","")
loo_Xml.UpdateAttrAt("soapenv:Body|def:getToken",1,"soapenv:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/")
loo_Xml.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.
loo_SbSoapXml = create oleobject
li_rc = loo_SbSoapXml.ConnectToNewObject("Chilkat.StringBuilder")
loo_SbSoapXml.Append(loo_Xml.GetXml())
li_NumReplaced = loo_SbXml.Replace("&","&")
li_NumReplaced = loo_SbXml.Replace(">",">")
li_NumReplaced = loo_SbXml.Replace("<","<")
li_NumReplaced = loo_SbXml.Replace("~"",""")
li_NumReplaced = loo_SbSoapXml.Replace("SIGNED_XML_GOES_HERE",loo_SbXml.GetAsString())
ls_XmlStr = loo_SbSoapXml.GetAsString()
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpStr("POST",ls_EndPoint,ls_XmlStr,"utf-8","text/xml",loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_XmlToSign
destroy loo_Gen
destroy loo_Cert
destroy loo_SbXml
destroy loo_Http
destroy loo_Xml
destroy loo_SbSoapXml
destroy loo_Resp
return
end if
li_ResponseStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code: " + string(li_ResponseStatusCode)
// You may examine the exact HTTP header sent with the POST like this:
Write-Debug "LastHeader:"
Write-Debug loo_Http.LastHeader
// Examine the XML returned by the web service:
Write-Debug "XML Response:"
loo_XmlResp = create oleobject
li_rc = loo_XmlResp.ConnectToNewObject("Chilkat.Xml")
loo_XmlResp.LoadXml(loo_Resp.BodyStr)
Write-Debug loo_XmlResp.GetXml()
// Use this online tool to generate parsing code from response XML:
// Generate Parsing Code from XML
destroy loo_XmlToSign
destroy loo_Gen
destroy loo_Cert
destroy loo_SbXml
destroy loo_Http
destroy loo_Xml
destroy loo_SbSoapXml
destroy loo_Resp
destroy loo_XmlResp