Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

VBScript Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
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
NTLM
OAuth1
OAuth2
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
PDF Signatures
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(VBScript) 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

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)

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

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

success = 1
' Create the XML to be signed...
set xmlToSign = CreateObject("Chilkat_9_5_0.Xml")
xmlToSign.Tag = "SOAP-ENV:Envelope"
success = xmlToSign.AddAttribute("xmlns:SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/")
xmlToSign.UpdateChildContent "SOAP-ENV:Header",""
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest",1,"xmlns","https://eFiskalizimi.tatime.gov.al/FiscalizationService/schema")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest",1,"xmlns:ns2","http://www.w3.org/2000/09/xmldsig#")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest",1,"Id","Request")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|Header",1,"SendDateTime","2019-09-03T14:19:01+02:00")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|Header",1,"UUID","42db3af5-0d9f-4dea-95b4-4b947ab8d8e7")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"BusinUnit","bb123bb123")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"DateTimeCreated","2019-09-03T14:19:01+02:00")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"DestinAddr","Destination address")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"DestinCity","Destination city")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"IsAfterDel","false")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"OperatorCode","oo123oo123")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"SoftNum","ss123ss123")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"StartAddr","Start address")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"StartCity","Start city")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"TransDate","2019-09-03T14:19:01+02:00")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"VehPlates","AA0000AA")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"WTNIC","5C5E58580D0A24E1F7A5E5E011929511")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"WTNICSignature","82D69C38206D ... F5FCA48")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"WTNNum","12345678901")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Issuer",1,"NUIS","I12345678I")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Issuer",1,"Name","Issuer name")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I",1,"C","501234567890")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I",1,"N","Item name")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I",1,"Q","1.0")
success = xmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I",1,"U","piece")

set gen = CreateObject("Chilkat_9_5_0.XmlDSigGen")

gen.SigLocation = "SOAP-ENV:Envelope|SOAP-ENV:Body|RegisterWTNRequest"
gen.SigLocationMod = 0
gen.SigNamespacePrefix = ""
gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#"
gen.SignedInfoCanonAlg = "EXCL_C14N"
gen.SignedInfoDigestMethod = "sha256"

' -------- Reference 1 --------
success = gen.AddSameDocRef("Request","sha256","EXCL_C14N","","")

' Provide a certificate + private key. (PFX password is test123)
set cert = CreateObject("Chilkat_9_5_0.Cert")
success = cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
If (success <> 1) Then
    outFile.WriteLine(cert.LastErrorText)
    WScript.Quit
End If

success = gen.SetX509Cert(cert,1)

gen.KeyInfoType = "X509Data"
gen.X509Type = "Certificate"

' Load XML to be signed...
set sbXml = CreateObject("Chilkat_9_5_0.StringBuilder")
success = xmlToSign.GetXmlSb(sbXml)

gen.Behaviors = "CompactSignedXml,ForceAddEnvelopedSignatureTransform"

' Sign the XML...
success = gen.CreateXmlDSigSb(sbXml)
If (success <> 1) Then
    outFile.WriteLine(gen.LastErrorText)
    WScript.Quit
End If

' -----------------------------------------------
' 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...

strXml = sbXml.GetAsString()

' 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..
set http = CreateObject("Chilkat_9_5_0.Http")
http.SetRequestHeader "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:
http.SetRequestHeader "Content-Type","text/xml; charset=utf-8"

' The testing endpoint for this soap service is likely:
endPoint = "https://efiskalizimi-test.tatime.gov.al/FiscalizationService-v1"

' resp is a Chilkat_9_5_0.HttpResponse
Set resp = http.PostXml(endPoint,strXml,"utf-8")
If (http.LastMethodSuccess <> 1) Then
    outFile.WriteLine(http.LastErrorText)
    outFile.WriteLine("LastHeader:")
    outFile.WriteLine(http.LastHeader)
    WScript.Quit
End If

responseStatusCode = resp.StatusCode

' Check that the responseStatusCode equals 200...
outFile.WriteLine("Response Status Code: " & responseStatusCode)

' Examine the exact HTTP header sent with the POST like this:
outFile.WriteLine("LastHeader:")
outFile.WriteLine(http.LastHeader)

' Examine the XML returned by the web service:
outFile.WriteLine("XML Response:")
set xmlResp = CreateObject("Chilkat_9_5_0.Xml")
success = xmlResp.LoadXml(resp.BodyStr)
outFile.WriteLine(xmlResp.GetXml())

' Use this online tool to generate parsing code from response XML: 
' Generate Parsing Code from XML


outFile.Close

 

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