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
(C) palena.sii.cl getToken SOAP RequestDemonstrates how to call getToken SOAP request at palena.sii.cl
#include <C_CkXml.h> #include <C_CkXmlDSigGen.h> #include <C_CkCert.h> #include <C_CkStringBuilder.h> #include <C_CkHttp.h> #include <C_CkHttpResponse.h> void ChilkatSample(void) { BOOL success; HCkXml xmlToSign; HCkXmlDSigGen gen; HCkCert cert; HCkStringBuilder sbXml; HCkHttp http; int responseStatusCode; const char *endPoint; HCkXml xml; HCkStringBuilder sbSoapXml; int numReplaced; HCkHttpResponse resp; HCkXml 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 = CkXml_Create(); CkXml_putTag(xmlToSign,"getToken"); // This is the seed obtained from palena.sii.cl getSeed CkXml_UpdateChildContent(xmlToSign,"item|Semilla","033878794660"); gen = CkXmlDSigGen_Create(); CkXmlDSigGen_putSigLocation(gen,"getToken"); CkXmlDSigGen_putSigLocationMod(gen,0); CkXmlDSigGen_putSigNamespacePrefix(gen,""); CkXmlDSigGen_putSigNamespaceUri(gen,"http://www.w3.org/2000/09/xmldsig#"); CkXmlDSigGen_putSignedInfoCanonAlg(gen,"EXCL_C14N"); CkXmlDSigGen_putSignedInfoDigestMethod(gen,"sha1"); CkXmlDSigGen_AddSameDocRef(gen,"","sha1","","",""); // Provide a certificate + private key. (PFX password is test123) cert = CkCert_Create(); success = CkCert_LoadPfxFile(cert,"qa_data/pfx/cert_test123.pfx","test123"); if (success != TRUE) { printf("%s\n",CkCert_lastErrorText(cert)); CkXml_Dispose(xmlToSign); CkXmlDSigGen_Dispose(gen); CkCert_Dispose(cert); return; } CkXmlDSigGen_SetX509Cert(gen,cert,TRUE); CkXmlDSigGen_putKeyInfoType(gen,"X509Data"); CkXmlDSigGen_putX509Type(gen,"Certificate"); // Load XML to be signed... sbXml = CkStringBuilder_Create(); CkXml_putEmitXmlDecl(xmlToSign,FALSE); CkXml_GetXmlSb(xmlToSign,sbXml); CkXmlDSigGen_putBehaviors(gen,"IndentedSignature"); // Sign the XML... success = CkXmlDSigGen_CreateXmlDSigSb(gen,sbXml); if (success != TRUE) { printf("%s\n",CkXmlDSigGen_lastErrorText(gen)); CkXml_Dispose(xmlToSign); CkXmlDSigGen_Dispose(gen); CkCert_Dispose(cert); CkStringBuilder_Dispose(sbXml); return; } // ----------------------------------------------- http = CkHttp_Create(); CkHttp_putUncommonOptions(http,"AllowEmptyHeaders"); CkHttp_SetRequestHeader(http,"SOAPAction",""); CkHttp_SetRequestHeader(http,"Content-Type","text/xml; charset=utf-8"); // The endpoint for this soap service is: endPoint = "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 = CkXml_Create(); CkXml_putTag(xml,"soapenv:Envelope"); CkXml_AddAttribute(xml,"xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); CkXml_AddAttribute(xml,"xmlns:xsd","http://www.w3.org/2001/XMLSchema"); CkXml_AddAttribute(xml,"xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/"); CkXml_AddAttribute(xml,"xmlns:def","http://DefaultNamespace"); CkXml_UpdateChildContent(xml,"soapenv:Header",""); CkXml_UpdateAttrAt(xml,"soapenv:Body|def:getToken",TRUE,"soapenv:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/"); CkXml_UpdateChildContent(xml,"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. sbSoapXml = CkStringBuilder_Create(); CkStringBuilder_Append(sbSoapXml,CkXml_getXml(xml)); numReplaced = CkStringBuilder_Replace(sbXml,"&","&"); numReplaced = CkStringBuilder_Replace(sbXml,">",">"); numReplaced = CkStringBuilder_Replace(sbXml,"<","<"); numReplaced = CkStringBuilder_Replace(sbXml,"\"","""); numReplaced = CkStringBuilder_Replace(sbSoapXml,"SIGNED_XML_GOES_HERE",CkStringBuilder_getAsString(sbXml)); resp = CkHttp_PostXml(http,endPoint,CkStringBuilder_getAsString(sbSoapXml),"utf-8"); if (CkHttp_getLastMethodSuccess(http) != TRUE) { printf("%s\n",CkHttp_lastErrorText(http)); printf("LastHeader:\n"); printf("%s\n",CkHttp_lastHeader(http)); CkXml_Dispose(xmlToSign); CkXmlDSigGen_Dispose(gen); CkCert_Dispose(cert); CkStringBuilder_Dispose(sbXml); CkHttp_Dispose(http); CkXml_Dispose(xml); CkStringBuilder_Dispose(sbSoapXml); return; } responseStatusCode = CkHttpResponse_getStatusCode(resp); printf("Response Status Code: %d\n",responseStatusCode); // You may examine the exact HTTP header sent with the POST like this: printf("LastHeader:\n"); printf("%s\n",CkHttp_lastHeader(http)); // Examine the XML returned by the web service: printf("XML Response:\n"); xmlResp = CkXml_Create(); CkXml_LoadXml(xmlResp,CkHttpResponse_bodyStr(resp)); printf("%s\n",CkXml_getXml(xmlResp)); // Use this online tool to generate parsing code from response XML: // Generate Parsing Code from XML CkHttpResponse_Dispose(resp); CkXml_Dispose(xmlToSign); CkXmlDSigGen_Dispose(gen); CkCert_Dispose(cert); CkStringBuilder_Dispose(sbXml); CkHttp_Dispose(http); CkXml_Dispose(xml); CkStringBuilder_Dispose(sbSoapXml); CkXml_Dispose(xmlResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.