Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Create Signed SOAP XML for Albanian Fiscalization ServiceImportant: 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.
integer li_rc integer li_Success oleobject loo_XmlToSign oleobject loo_Gen oleobject loo_Cert oleobject loo_SbXml string ls_StrXml integer li_ResponseStatusCode oleobject loo_Http string ls_EndPoint oleobject loo_Resp oleobject loo_XmlResp // 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> li_Success = 1 // Create the XML to be signed... loo_XmlToSign = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 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 = "SOAP-ENV:Envelope" loo_XmlToSign.AddAttribute("xmlns:SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/") loo_XmlToSign.UpdateChildContent("SOAP-ENV:Header","") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest",1,"xmlns","https://eFiskalizimi.tatime.gov.al/FiscalizationService/schema") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest",1,"xmlns:ns2","http://www.w3.org/2000/09/xmldsig#") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest",1,"Id","Request") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|Header",1,"SendDateTime","2019-09-03T14:19:01+02:00") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|Header",1,"UUID","42db3af5-0d9f-4dea-95b4-4b947ab8d8e7") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"BusinUnit","bb123bb123") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"DateTimeCreated","2019-09-03T14:19:01+02:00") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"DestinAddr","Destination address") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"DestinCity","Destination city") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"IsAfterDel","false") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"OperatorCode","oo123oo123") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"SoftNum","ss123ss123") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"StartAddr","Start address") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"StartCity","Start city") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"TransDate","2019-09-03T14:19:01+02:00") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"VehPlates","AA0000AA") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"WTNIC","5C5E58580D0A24E1F7A5E5E011929511") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"WTNICSignature","82D69C38206D ... F5FCA48") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN",1,"WTNNum","12345678901") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Issuer",1,"NUIS","I12345678I") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Issuer",1,"Name","Issuer name") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I",1,"C","501234567890") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I",1,"N","Item name") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I",1,"Q","1.0") loo_XmlToSign.UpdateAttrAt("SOAP-ENV:Body|RegisterWTNRequest|WTN|Items|I",1,"U","piece") loo_Gen = create oleobject // Use "Chilkat_9_5_0.XmlDSigGen" for versions of Chilkat < 10.0.0 li_rc = loo_Gen.ConnectToNewObject("Chilkat.XmlDSigGen") loo_Gen.SigLocation = "SOAP-ENV:Envelope|SOAP-ENV:Body|RegisterWTNRequest" 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 = "sha256" // -------- Reference 1 -------- loo_Gen.AddSameDocRef("Request","sha256","EXCL_C14N","","") // Provide a certificate + private key. (PFX password is test123) loo_Cert = create oleobject // Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert") li_Success = loo_Cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123") if li_Success <> 1 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 // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder") loo_XmlToSign.GetXmlSb(loo_SbXml) loo_Gen.Behaviors = "CompactSignedXml,ForceAddEnvelopedSignatureTransform" // Sign the XML... li_Success = loo_Gen.CreateXmlDSigSb(loo_SbXml) if li_Success <> 1 then Write-Debug loo_Gen.LastErrorText destroy loo_XmlToSign destroy loo_Gen destroy loo_Cert destroy loo_SbXml return 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... ls_StrXml = loo_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.. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") loo_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: loo_Http.SetRequestHeader("Content-Type","text/xml; charset=utf-8") // The testing endpoint for this soap service is likely: ls_EndPoint = "https://efiskalizimi-test.tatime.gov.al/FiscalizationService-v1" loo_Resp = loo_Http.PostXml(ls_EndPoint,ls_StrXml,"utf-8") if loo_Http.LastMethodSuccess <> 1 then Write-Debug loo_Http.LastErrorText Write-Debug "LastHeader:" Write-Debug loo_Http.LastHeader destroy loo_XmlToSign destroy loo_Gen destroy loo_Cert destroy loo_SbXml destroy loo_Http return end if li_ResponseStatusCode = loo_Resp.StatusCode // Check that the responseStatusCode equals 200... Write-Debug "Response Status Code: " + string(li_ResponseStatusCode) // 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 // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 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_Resp destroy loo_XmlToSign destroy loo_Gen destroy loo_Cert destroy loo_SbXml destroy loo_Http destroy loo_XmlResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.