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
(Unicode C) palena.sii.cl getToken SOAP RequestDemonstrates how to call getToken SOAP request at palena.sii.cl
#include <C_CkXmlW.h> #include <C_CkXmlDSigGenW.h> #include <C_CkCertW.h> #include <C_CkStringBuilderW.h> #include <C_CkHttpW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { BOOL success; HCkXmlW xmlToSign; HCkXmlDSigGenW gen; HCkCertW cert; HCkStringBuilderW sbXml; HCkHttpW http; int responseStatusCode; const wchar_t *endPoint; HCkXmlW xml; HCkStringBuilderW sbSoapXml; int numReplaced; HCkHttpResponseW resp; HCkXmlW xmlResp; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Create the XML to be signed... xmlToSign = CkXmlW_Create(); CkXmlW_putTag(xmlToSign,L"getToken"); // This is the seed obtained from palena.sii.cl getSeed CkXmlW_UpdateChildContent(xmlToSign,L"item|Semilla",L"033878794660"); gen = CkXmlDSigGenW_Create(); CkXmlDSigGenW_putSigLocation(gen,L"getToken"); CkXmlDSigGenW_putSigLocationMod(gen,0); CkXmlDSigGenW_putSigNamespacePrefix(gen,L""); CkXmlDSigGenW_putSigNamespaceUri(gen,L"http://www.w3.org/2000/09/xmldsig#"); CkXmlDSigGenW_putSignedInfoCanonAlg(gen,L"EXCL_C14N"); CkXmlDSigGenW_putSignedInfoDigestMethod(gen,L"sha1"); CkXmlDSigGenW_AddSameDocRef(gen,L"",L"sha1",L"",L"",L""); // Provide a certificate + private key. (PFX password is test123) cert = CkCertW_Create(); success = CkCertW_LoadPfxFile(cert,L"qa_data/pfx/cert_test123.pfx",L"test123"); if (success != TRUE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkXmlW_Dispose(xmlToSign); CkXmlDSigGenW_Dispose(gen); CkCertW_Dispose(cert); return; } CkXmlDSigGenW_SetX509Cert(gen,cert,TRUE); CkXmlDSigGenW_putKeyInfoType(gen,L"X509Data"); CkXmlDSigGenW_putX509Type(gen,L"Certificate"); // Load XML to be signed... sbXml = CkStringBuilderW_Create(); CkXmlW_putEmitXmlDecl(xmlToSign,FALSE); CkXmlW_GetXmlSb(xmlToSign,sbXml); CkXmlDSigGenW_putBehaviors(gen,L"IndentedSignature"); // Sign the XML... success = CkXmlDSigGenW_CreateXmlDSigSb(gen,sbXml); if (success != TRUE) { wprintf(L"%s\n",CkXmlDSigGenW_lastErrorText(gen)); CkXmlW_Dispose(xmlToSign); CkXmlDSigGenW_Dispose(gen); CkCertW_Dispose(cert); CkStringBuilderW_Dispose(sbXml); return; } // ----------------------------------------------- http = CkHttpW_Create(); CkHttpW_putUncommonOptions(http,L"AllowEmptyHeaders"); CkHttpW_SetRequestHeader(http,L"SOAPAction",L""); CkHttpW_SetRequestHeader(http,L"Content-Type",L"text/xml; charset=utf-8"); // The endpoint for this soap service is: endPoint = L"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> xml = CkXmlW_Create(); CkXmlW_putTag(xml,L"soapenv:Envelope"); CkXmlW_AddAttribute(xml,L"xmlns:xsi",L"http://www.w3.org/2001/XMLSchema-instance"); CkXmlW_AddAttribute(xml,L"xmlns:xsd",L"http://www.w3.org/2001/XMLSchema"); CkXmlW_AddAttribute(xml,L"xmlns:soapenv",L"http://schemas.xmlsoap.org/soap/envelope/"); CkXmlW_AddAttribute(xml,L"xmlns:def",L"http://DefaultNamespace"); CkXmlW_UpdateChildContent(xml,L"soapenv:Header",L""); CkXmlW_UpdateAttrAt(xml,L"soapenv:Body|def:getToken",TRUE,L"soapenv:encodingStyle",L"http://schemas.xmlsoap.org/soap/encoding/"); CkXmlW_UpdateChildContent(xml,L"soapenv:Body|def:getToken|pszXml",L"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. sbSoapXml = CkStringBuilderW_Create(); CkStringBuilderW_Append(sbSoapXml,CkXmlW_getXml(xml)); numReplaced = CkStringBuilderW_Replace(sbXml,L"&",L"&"); numReplaced = CkStringBuilderW_Replace(sbXml,L">",L">"); numReplaced = CkStringBuilderW_Replace(sbXml,L"<",L"<"); numReplaced = CkStringBuilderW_Replace(sbXml,L"\"",L"""); numReplaced = CkStringBuilderW_Replace(sbSoapXml,L"SIGNED_XML_GOES_HERE",CkStringBuilderW_getAsString(sbXml)); resp = CkHttpW_PostXml(http,endPoint,CkStringBuilderW_getAsString(sbSoapXml),L"utf-8"); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); wprintf(L"LastHeader:\n"); wprintf(L"%s\n",CkHttpW_lastHeader(http)); CkXmlW_Dispose(xmlToSign); CkXmlDSigGenW_Dispose(gen); CkCertW_Dispose(cert); CkStringBuilderW_Dispose(sbXml); CkHttpW_Dispose(http); CkXmlW_Dispose(xml); CkStringBuilderW_Dispose(sbSoapXml); return; } responseStatusCode = CkHttpResponseW_getStatusCode(resp); wprintf(L"Response Status Code: %d\n",responseStatusCode); // You may examine the exact HTTP header sent with the POST like this: wprintf(L"LastHeader:\n"); wprintf(L"%s\n",CkHttpW_lastHeader(http)); // Examine the XML returned by the web service: wprintf(L"XML Response:\n"); xmlResp = CkXmlW_Create(); CkXmlW_LoadXml(xmlResp,CkHttpResponseW_bodyStr(resp)); wprintf(L"%s\n",CkXmlW_getXml(xmlResp)); // Use this online tool to generate parsing code from response XML: // Generate Parsing Code from XML CkHttpResponseW_Dispose(resp); CkXmlW_Dispose(xmlToSign); CkXmlDSigGenW_Dispose(gen); CkCertW_Dispose(cert); CkStringBuilderW_Dispose(sbXml); CkHttpW_Dispose(http); CkXmlW_Dispose(xml); CkStringBuilderW_Dispose(sbSoapXml); CkXmlW_Dispose(xmlResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.