Rust
Rust
palena.sii.cl getToken SOAP Request
See more SII Chile Examples
Demonstrates how to call getToken SOAP request at palena.sii.clChilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Create the XML to be signed...
let xml_to_sign = chilkat::Xml::new();
xml_to_sign.set_tag("getToken");
// This is the seed obtained from palena.sii.cl getSeed
xml_to_sign.update_child_content("item|Semilla", "033878794660");
let gen_ = chilkat::XmlDSigGen::new();
gen_.set_sig_location("getToken");
gen_.set_sig_location_mod(0);
gen_.set_sig_namespace_prefix("");
gen_.set_sig_namespace_uri("http://www.w3.org/2000/09/xmldsig#");
gen_.set_signed_info_canon_alg("EXCL_C14N");
gen_.set_signed_info_digest_method("sha1");
let _ = gen_.add_same_doc_ref("", "sha1", "", "", "");
// Provide a certificate + private key. (PFX password is test123)
let cert = chilkat::Cert::new();
if cert.load_pfx_file("qa_data/pfx/cert_test123.pfx", "test123").is_err() {
println!("{}", cert.last_error_text());
return;
}
let _ = gen_.set_x509_cert(&cert, true);
gen_.set_key_info_type("X509Data");
gen_.set_x509_type("Certificate");
// Load XML to be signed...
let sb_xml = chilkat::StringBuilder::new();
xml_to_sign.set_emit_xml_decl(false);
let _ = xml_to_sign.get_xml_sb(&sb_xml);
gen_.set_behaviors("IndentedSignature");
// Sign the XML...
if gen_.create_xml_d_sig_sb(&sb_xml).is_err() {
println!("{}", gen_.last_error_text());
return;
}
// -----------------------------------------------
let http = chilkat::Http::new();
http.set_uncommon_options("AllowEmptyHeaders");
http.set_request_header("SOAPAction", "");
// The endpoint for this soap service is:
let end_point = "https://palena.sii.cl/DTEWS/GetTokenFromSeed.jws".to_string();
// 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>
let xml = chilkat::Xml::new();
xml.set_tag("soapenv:Envelope");
let _ = xml.add_attribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
let _ = xml.add_attribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
let _ = xml.add_attribute("xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
let _ = xml.add_attribute("xmlns:def", "http://DefaultNamespace");
xml.update_child_content("soapenv:Header", "");
let _ = xml.update_attr_at("soapenv:Body|def:getToken", true, "soapenv:encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/");
xml.update_child_content("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.
let sb_soap_xml = chilkat::StringBuilder::new();
let _ = sb_soap_xml.append(&xml.get_xml().unwrap_or_default());
let mut num_replaced = sb_xml.replace("&", "&");
num_replaced = sb_xml.replace(">", ">");
num_replaced = sb_xml.replace("<", "<");
num_replaced = sb_xml.replace("\"", """);
num_replaced = sb_soap_xml.replace("SIGNED_XML_GOES_HERE", &sb_xml.get_as_string().unwrap_or_default());
let xml_str = sb_soap_xml.get_as_string().unwrap_or_default();
let resp = chilkat::HttpResponse::new();
if http.http_str("POST", &end_point, &xml_str, "utf-8", "text/xml", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let response_status_code = resp.status_code();
println!("Response Status Code: {}", response_status_code);
// You may examine the exact HTTP header sent with the POST like this:
println!("LastHeader:");
println!("{}", http.last_header());
// Examine the XML returned by the web service:
println!("XML Response:");
let xml_resp = chilkat::Xml::new();
let _ = xml_resp.load_xml(&resp.body_str());
println!("{}", xml_resp.get_xml().unwrap_or_default());
// Use this online tool to generate parsing code from response XML:
// Generate Parsing Code from XML