Rust
Rust
SOAP sendBill Call to sunat.gob.pe
See more HTTP Misc Examples
Demonstrates how to make a SOAP call to sunat.gob.pe for the sendBill method.Chilkat Rust Downloads
// This example requires 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.
// --------------------------------------------------------------------------------
let http = chilkat::Http::new();
// The SOAP XML will look like this:
// <?xml version="1.0" encoding="utf-8"?>
// <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.sunat.gob.pe">
// <soapenv:Header/>
//
// <soapenv:Body>
// <ser:sendBill>
// <fileName>20601523999-03-B001-00000002.zip</fileName>
// <contentFile>UEsDBBQ ... AAAAA==</contentFile>
// </ser:sendBill>
// </soapenv:Body>
// </soapenv:Envelope>
// Build the above SOAP XML.
let xml = chilkat::Xml::new();
xml.set_tag("soapenv:Envelope");
let _ = xml.add_attribute("xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
let _ = xml.add_attribute("xmlns:ser", "http://service.sunat.gob.pe");
xml.update_child_content("soapenv:Header", "");
xml.update_child_content("soapenv:Body|ser:sendBill|fileName", "20601523999-03-B001-00000002.zip");
xml.update_child_content("soapenv:Body|ser:sendBill|contentFile", "UEsDBBQ ... AAAAA==");
// Alternatively, load the XML from a file. (Remove this line if you wish to build the XML as shown above.)
let _ = xml.load_xml_file("qa_data/soap/envio_sunat_peru.xml").is_ok();
let str_xml = xml.get_xml().unwrap_or_default();
http.set_request_header("SOAPAction", "urn:sendBill");
let end_point = "https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService".to_string();
let resp = chilkat::HttpResponse::new();
if http.http_str("POST", &end_point, &str_xml, "utf-8", "text/xml", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let response_status_code = resp.status_code();
// You may wish to verify that the responseStatusCode equals 200...
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