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 Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(DataFlex) Create Signed SOAP XML for Albanian Fiscalization Service

Important: This example requires Chilkat v9.5.0.80 or greater.

This example is created for a customer that needs to send signed billing/invoicing SOAP XML requests to http://efiskalizimi-test.tatime.gov.al:80/FiscalizationService

The example demonstrates how to create and signed the SOAP XML message that is to be sent.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoXmlToSign
    Handle hoGen
    Variant vCert
    Handle hoCert
    Variant vSbXml
    Handle hoSbXml
    String sStrXml
    Integer iResponseStatusCode
    Handle hoHttp
    String sEndPoint
    Variant vResp
    Handle hoResp
    Handle hoXmlResp
    String sTemp1
    Boolean bTemp1

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // --------------------------------------------------------------------------------
    // Also see Chilkat's Online WSDL Code Generator
    // to generate code and SOAP Request and Response XML for each operation in a WSDL.
    // --------------------------------------------------------------------------------

    // We want to build and send a signed SOAP XML that looks like the following:

    // 
    // <?xml version="1.0" encoding="utf-8"?>
    // <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    //     <SOAP-ENV:Header/>
    //     <SOAP-ENV:Body>
    //         <RegisterWTNRequest xmlns="https://eFiskalizimi.tatime.gov.al/FiscalizationService/schema" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" Id="Request">
    //             <Header SendDateTime="2019-09-03T14:19:01+02:00" UUID="42db3af5-0d9f-4dea-95b4-4b947ab8d8e7"/>
    //             <WTN BusinUnit="bb123bb123" DateTimeCreated="2019-09-03T14:19:01+02:00" DestinAddr="Destination address" 
    // 			DestinCity="Destination city" IsAfterDel="false" OperatorCode="oo123oo123" 
    // 			SoftNum="ss123ss123" StartAddr="Start address" StartCity="Start city" TransDate="2019-09-03T14:19:01+02:00" 
    // 			VehPlates="AA0000AA" WTNIC="5C5E58580D0A24E1F7A5E5E011929511" WTNICSignature="82D69C38206D ... F5FCA48" WTNNum="12345678901">
    //                 <Issuer NUIS="I12345678I" Name="Issuer name"/>
    //                 <Items>
    //                     <I C="501234567890" N="Item name" Q="1.0" U="piece"/>
    //                 </Items>
    //             </WTN>
    //             <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
    //                 <SignedInfo>
    //                     <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    //                     <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
    //                     <Reference URI="#Request">
    //                         <Transforms>
    //                             <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
    //                             <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    //                         </Transforms>
    //                         <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
    //                         <DigestValue>aNa0r4RW04BlsAciTUrWHGW9PADskl2op315BAQ0hTg=</DigestValue>
    //                     </Reference>
    //                 </SignedInfo>
    //                 <SignatureValue>4/j/d4j/5xCJ2YUP+XTC6li0B94...........................KESd38NT5+puArBcNgLYIjLx/dh6Q==</SignatureValue>
    //                 <KeyInfo>
    //                     <X509Data>
    //                         <X509Certificate>MIIE6TCCAtGgAwIBAgICEA8wDQYJKoZIhvcNA......................uoqWsSuLmA==</X509Certificate>
    //                     </X509Data>
    //                 </KeyInfo>
    //             </Signature>
    //         </RegisterWTNRequest>
    //     </SOAP-ENV:Body>
    // </SOAP-ENV:Envelope>

    Move True To iSuccess
    // 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 "SOAP-ENV:Envelope"
    Get ComAddAttribute Of hoXmlToSign "xmlns:SOAP-ENV" "http://schemas.xmlsoap.org/soap/envelope/" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "SOAP-ENV:Header" ""
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest" True "xmlns" "https://eFiskalizimi.tatime.gov.al/FiscalizationService/schema" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest" True "xmlns:ns2" "http://www.w3.org/2000/09/xmldsig#" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest" True "Id" "Request" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|Header" True "SendDateTime" "2019-09-03T14:19:01+02:00" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|Header" True "UUID" "42db3af5-0d9f-4dea-95b4-4b947ab8d8e7" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "BusinUnit" "bb123bb123" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "DateTimeCreated" "2019-09-03T14:19:01+02:00" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "DestinAddr" "Destination address" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "DestinCity" "Destination city" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "IsAfterDel" "false" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "OperatorCode" "oo123oo123" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "SoftNum" "ss123ss123" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "StartAddr" "Start address" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "StartCity" "Start city" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "TransDate" "2019-09-03T14:19:01+02:00" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "VehPlates" "AA0000AA" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "WTNIC" "5C5E58580D0A24E1F7A5E5E011929511" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "WTNICSignature" "82D69C38206D ... F5FCA48" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN" True "WTNNum" "12345678901" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN|Issuer" True "NUIS" "I12345678I" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN|Issuer" True "Name" "Issuer name" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I" True "C" "501234567890" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I" True "N" "Item name" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I" True "Q" "1.0" To iSuccess
    Get ComUpdateAttrAt Of hoXmlToSign "SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I" True "U" "piece" To iSuccess

    Get Create (RefClass(cComChilkatXmlDSigGen)) To hoGen
    If (Not(IsComObjectCreated(hoGen))) Begin
        Send CreateComObject of hoGen
    End

    Set ComSigLocation Of hoGen To "SOAP-ENV:Envelope|SOAP-ENV:Body|RegisterWTNRequest"
    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 "sha256"

    // -------- Reference 1 --------
    Get ComAddSameDocRef Of hoGen "Request" "sha256" "EXCL_C14N" "" "" 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
    Get pvComObject of hoSbXml to vSbXml
    Get ComGetXmlSb Of hoXmlToSign vSbXml To iSuccess

    Set ComBehaviors Of hoGen To "CompactSignedXml,ForceAddEnvelopedSignatureTransform"

    // 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

    // -----------------------------------------------
    // Now to send the SOAP request....

    // Note: Chilkat did not actually test this by sending the request to the server.
    // The example is a best-guess for how to do it...

    Get ComGetAsString Of hoSbXml To sStrXml

    // We'll need to add this in the HTTP header:
    // SOAPAction: "https://eFiskalizimi.tatime.gov.al/FiscalizationService/RegisterWTN"

    // Note: This is for the RegisterWTN request.

    // You may wish to load the WSDL at https://efiskalizimi-test.tatime.gov.al/FiscalizationService-v1/FiscalizationService.wsdl into the SoapUI application to see 
    // the SOAP requests..
    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Send ComSetRequestHeader To hoHttp "SOAPAction" "https://eFiskalizimi.tatime.gov.al/FiscalizationService/RegisterWTN"

    // Some services expect the content-type in the HTTP header to be "application/xml" while
    // other expect text/xml.  The default sent by Chilkat is "application/xml", but this web service
    // likely expects "text/xml".  Therefore, change the content-type:
    Send ComSetRequestHeader To hoHttp "Content-Type" "text/xml; charset=utf-8"

    // The testing endpoint for this soap service is likely:
    Move "https://efiskalizimi-test.tatime.gov.al/FiscalizationService-v1" To sEndPoint

    Get ComPostXml Of hoHttp sEndPoint sStrXml "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

    // Check that the responseStatusCode equals 200...
    Showln "Response Status Code: " iResponseStatusCode

    // 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-2024 Chilkat Software, Inc. All Rights Reserved.