Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
Mastercard
MedTunnel

MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
Trello
Twilio
Twitter API v2
Twitter v1
UniPin
VoiceBase
Vonage
WaTrend
Walmart
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(DataFlex) palena.sii.cl getToken SOAP Request

Demonstrates how to call getToken SOAP request at palena.sii.cl

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-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
    Variant vResp
    Handle hoResp
Resp    Handle hoXmlResp
    String sTemp1
    Boolean bTemp1

    // 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 <> True) 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 <> True) 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" ""

    Send ComSetRequestHeader To hoHttp "Content-Type" "text/xml; charset=utf-8"

    // 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 "&" "&amp;" To iNumReplaced
    Get ComReplace Of hoSbXml ">" "&gt;" To iNumReplaced
    Get ComReplace Of hoSbXml "<" "&lt;" To iNumReplaced
    Get ComReplace Of hoSbXml '"' "&quot;" To iNumReplaced
    Get ComGetAsString Of hoSbXml To sTemp1
    Get ComReplace Of hoSbSoapXml "SIGNED_XML_GOES_HERE" sTemp1 To iNumReplaced

    Get ComGetAsString Of hoSbSoapXml To sTemp1
    Get ComPostXml Of hoHttp sEndPoint sTemp1 "utf-8" To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Showln "LastHeader:"
        Get ComLastHeader 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

    Send Destroy of hoResp


End_Procedure

 

© 2000-2023 Chilkat Software, Inc. All Rights Reserved.