Unicode C
Unicode C
Yet Another SOAP MTOM POST Example
See more HTTP Misc Examples
Demonstrates how to sending a SOAP request with an MTOM/XOP attachment...Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkXmlW.h>
#include <C_CkHttpRequestW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkXmlW xml;
HCkHttpRequestW req;
BOOL useTls;
HCkHttpResponseW resp;
HCkXmlW xmlResponse;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// First build the following XML:
// <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
// xmlns:imp="http://www.yourdomain.it/ImportMultiploWorkflowPAWS/">
// <soapenv:Header/>
// <soapenv:Body>
// <imp:InputImportMultiploWorkflowPA>
// <usernameEis>MyUsername</usernameEis>
// <passwordEis>MyPassword</passwordEis>
// <postazioneEis>COSO00</postazioneEis>
// <istitutoEis>COSO</istitutoEis>
// <codiceAzienda>COSO0000</codiceAzienda>
// <fileZip><inc:Include href="cid:780931946797" xmlns:inc="http://www.w3.org/2004/08/xop/include"/></fileZip>
// <fileZipName>IT04769180151_00044.zip</fileZipName>
// <workflow>carica</workflow>
// </imp:InputImportMultiploWorkflowPA>
// </soapenv:Body>
// </soapenv:Envelope>
xml = CkXmlW_Create();
CkXmlW_putTag(xml,L"soapenv:Envelope");
CkXmlW_AddAttribute(xml,L"xmlns:soapenv",L"http://schemas.xmlsoap.org/soap/envelope/");
CkXmlW_AddAttribute(xml,L"xmlns:imp",L"http://www.yourdomain.it/ImportMultiploWorkflowPAWS/");
CkXmlW_UpdateChildContent(xml,L"soapenv:Header",L"");
CkXmlW_UpdateChildContent(xml,L"soapenv:Body|imp:InputImportMultiploWorkflowPA|usernameEis",L"MyUsername");
CkXmlW_UpdateChildContent(xml,L"soapenv:Body|imp:InputImportMultiploWorkflowPA|passwordEis",L"MyPassword");
CkXmlW_UpdateChildContent(xml,L"soapenv:Body|imp:InputImportMultiploWorkflowPA|postazioneEis",L"COSO00");
CkXmlW_UpdateChildContent(xml,L"soapenv:Body|imp:InputImportMultiploWorkflowPA|istitutoEis",L"COSO");
CkXmlW_UpdateChildContent(xml,L"soapenv:Body|imp:InputImportMultiploWorkflowPA|codiceAzienda",L"COSO0000");
CkXmlW_UpdateAttrAt(xml,L"soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZip|inc:Include",TRUE,L"href",L"cid:780931946797");
CkXmlW_UpdateAttrAt(xml,L"soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZip|inc:Include",TRUE,L"xmlns:inc",L"http://www.w3.org/2004/08/xop/include");
CkXmlW_UpdateChildContent(xml,L"soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZipName",L"IT04769180151_00044.zip");
CkXmlW_UpdateChildContent(xml,L"soapenv:Body|imp:InputImportMultiploWorkflowPA|workflow",L"carica");
// We want our top-level HTTP request header to look like this:
// POST /http-router-softwarehubsystem/webservices/importMultiploWorkflowPA HTTP/1.1
// Accept-Encoding: gzip,deflate
// Content-Type: multipart/related; type="application/xop+xml"; start="<rootpart@soapui.org>"; start-info="text/xml"; boundary="----=_Part_0_1353857996.1546013984933"
// SOAPAction: "http://www.yourdomain.it/ImportMultiploWorkflowPAWS/importMultiploWorkflowPA"
// MIME-Version: 1.0
// Content-Length: <chilkat will add this header>
// Host: <chilkat will add this header>
// Connection: Keep-Alive
// User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
req = CkHttpRequestW_Create();
CkHttpRequestW_putHttpVerb(req,L"POST");
CkHttpRequestW_putPath(req,L"/http-router-softwarehubsystem/webservices/importMultiploWorkflowPA");
CkHttpRequestW_putContentType(req,L"multipart/related; type=\"application/xop+xml\"; start=\"<rootpart@soapui.org>\"; start-info=\"text/xml\"");
CkHttpRequestW_AddHeader(req,L"SOAPAction",L"\"http://www.yourdomain.it/ImportMultiploWorkflowPAWS/importMultiploWorkflowPA\"");
CkHttpRequestW_AddHeader(req,L"Accept-Encoding",L"gzip,deflate");
CkHttpRequestW_AddHeader(req,L"Mime-Version",L"1.0");
CkHttpRequestW_AddHeader(req,L"Connection",L"Keep-Alive");
CkHttpRequestW_AddHeader(req,L"User-Agent",L"Apache-HttpClient/4.1.1 (java 1.5)");
// Add the XML content for the 1st MIME sub-part.
CkXmlW_putEmitXmlDecl(xml,FALSE);
CkXmlW_putEmitCompact(xml,FALSE);
success = CkHttpRequestW_AddStringForUpload2(req,L"",L"",CkXmlW_getXml(xml),L"utf-8",L"application/xop+xml; charset=UTF-8; type=\"text/xml\"");
// We want the 1st sub-header (the sub-part containing the XML) to look like this:
// Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
// Content-Transfer-Encoding: 8bit
// Content-ID: <rootpart@soapui.org>
// Make sure we set sub-headers *after* calling AddStringForUpload2, otherwise AddStringForUpload2 might change these explicitly set headers.
success = CkHttpRequestW_AddSubHeader(req,0,L"Content-Transfer-Encoding",L"8bit");
success = CkHttpRequestW_AddSubHeader(req,0,L"Content-ID",L"<rootpart@soapui.org>");
// Add a reference to the local file for the file data for the 2nd MIME sub-part.
success = CkHttpRequestW_AddFileForUpload2(req,L"",L"qa_data/zips/helloWorld.zip",L"application/zip; name=IT04769180151_00044.zip");
// We want the 2nd sub-header (for the MIME sub-part containing a .zip file) to look like this:
// Content-Type: application/zip; name=IT04769180151_00044.zip
// Content-Transfer-Encoding: binary
// Content-ID: <IT04769180151_00044.zip>
// Content-Disposition: attachment; name="IT04769180151_00044.zip"; filename="IT04769180151_00044.zip"
// Make sure we set sub-headers *after* calling AddFileForUpload2, otherwise AddFileForUpload2 might change these explicitly set headers.
success = CkHttpRequestW_AddSubHeader(req,1,L"Content-Transfer-Encoding",L"binary");
success = CkHttpRequestW_AddSubHeader(req,1,L"Content-ID",L"<IT04769180151_00044.zip>");
success = CkHttpRequestW_AddSubHeader(req,1,L"Content-Disposition",L"attachment; name=\"IT04769180151_00044.zip\"; filename=\"IT04769180151_00044.zip\"");
// Keep a session log so we can examine the exact request/response.
// Remove this line when finished with debugging.
CkHttpW_putSessionLogFilename(http,L"qa_output/mtom_sessionLog.txt");
useTls = FALSE;
// Note: Please don't run this example without changing the domain to your own domain...
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpSReq(http,L"www.yourdomain.it",80,useTls,req,resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkXmlW_Dispose(xml);
CkHttpRequestW_Dispose(req);
CkHttpResponseW_Dispose(resp);
return;
}
xmlResponse = CkXmlW_Create();
success = CkXmlW_LoadXml(xmlResponse,CkHttpResponseW_bodyStr(resp));
// println xmlResponse.GetXml();
wprintf(L"OK.\n");
CkHttpW_Dispose(http);
CkXmlW_Dispose(xml);
CkHttpRequestW_Dispose(req);
CkHttpResponseW_Dispose(resp);
CkXmlW_Dispose(xmlResponse);
}