Sample code for 30+ languages & platforms
Unicode C

BaFin MVP Portal SOAP Web Service MTOM

See more REST Misc Examples

Demonstrate how to send a SOAP request with MTOM attachment to the BaFin MVP Portal as indicated at https://www.bafin.de/SharedDocs/Downloads/EN/dl_mvp-portal_soap_webservice_a26mifir_en.pdf

Chilkat Unicode C Downloads

Unicode C
#include <C_CkRestW.h>
#include <C_CkXmlW.h>
#include <C_CkBinDataW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkRestW rest;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkXmlW soapXml;
    const wchar_t *responseBody;
    HCkBinDataW bdRequest;

    success = FALSE;

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    rest = CkRestW_Create();

    //  Connect to portal.mvp.bafin.de:444
    bTls = TRUE;
    port = 444;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"portal.mvp.bafin.de",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    //  The SOAP request we'll be sending is multipart/related and it will have two parts
    //  1) the SOAP Envelope
    //  2) the MTOM attachment (in this case an XML document)

    //  Let's build the SOAP envelope:
    //  Note: The data posted here, including the username, are not actual accounts.  It is the sample data provided
    //  at https://www.bafin.de/SharedDocs/Downloads/EN/dl_mvp-portal_soap_webservice_a26mifir_en.pdf

    //  Use this online tool to generate code from sample XML: 
    //  Generate Code to Create XML

    soapXml = CkXmlW_Create();
    CkXmlW_putTag(soapXml,L"soapenv:Envelope");
    CkXmlW_AddAttribute(soapXml,L"xmlns:a26mifir",L"http://www.bafin.de/mvp/a26mifir/");
    CkXmlW_AddAttribute(soapXml,L"xmlns:soapenv",L"http://schemas.xmlsoap.org/soap/envelope/");
    CkXmlW_UpdateAttrAt(soapXml,L"soapenv:Header|wsse:Security",TRUE,L"soapenv:mustUnderstand",L"1");
    CkXmlW_UpdateAttrAt(soapXml,L"soapenv:Header|wsse:Security",TRUE,L"xmlns:wsse",L"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
    CkXmlW_UpdateAttrAt(soapXml,L"soapenv:Header|wsse:Security",TRUE,L"xmlns:wsu",L"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurityutility-1.0.xsd");
    CkXmlW_UpdateAttrAt(soapXml,L"soapenv:Header|wsse:Security|wsse:UsernameToken",TRUE,L"wsu:Id",L"UsernameToken44C3662D584567FE6A14672949268541");
    CkXmlW_UpdateChildContent(soapXml,L"soapenv:Header|wsse:Security|wsse:UsernameToken|wsse:Username",L"karl.meier1234#hg_05_1234567890");
    CkXmlW_UpdateAttrAt(soapXml,L"soapenv:Header|wsse:Security|wsse:UsernameToken|wsse:Password",TRUE,L"Type",L"http://docs.oasis-open.org/wss/2004/01/oasis200401-wss-username-token-profile-1.0#PasswordText");
    CkXmlW_UpdateChildContent(soapXml,L"soapenv:Header|wsse:Security|wsse:UsernameToken|wsse:Password",L"XXXXXXXXXX");
    CkXmlW_UpdateAttrAt(soapXml,L"soapenv:Header|wsse:Security|wsse:UsernameToken|wsse:Nonce",TRUE,L"EncodingType",L"http://docs.oasis-open.org/wss/2004/01/oasis200401-wss-soap-message-security1.0#Base64Binary");
    CkXmlW_UpdateChildContent(soapXml,L"soapenv:Header|wsse:Security|wsse:UsernameToken|wsse:Nonce",L"+WifMh5kFw/1fHgMahFu7A==");
    CkXmlW_UpdateChildContent(soapXml,L"soapenv:Header|wsse:Security|wsse:UsernameToken|wsu:Created",L"2016-06-30T13:55:26.852Z");
    CkXmlW_UpdateChildContent(soapXml,L"soapenv:Body|a26mifir:submitDATTRA|inDATTRA|a26mifir:dateiname",L"A26MiFIR_Testfile_001.xml");
    CkXmlW_UpdateChildContent(soapXml,L"soapenv:Body|a26mifir:submitDATTRA|kundenreferenz",L"ClientRef_001");
    CkXmlW_UpdateAttrAt(soapXml,L"soapenv:Body|a26mifir:submitDATTRA|datei|inc:Include",TRUE,L"href",L"cid:139580394822");
    CkXmlW_UpdateAttrAt(soapXml,L"soapenv:Body|a26mifir:submitDATTRA|datei|inc:Include",TRUE,L"xmlns:inc",L"http://www.w3.org/2004/08/xop/include");

    //  We built the following XML:

    //  <?xml version="1.0" encoding="utf-8"?>
    //  <soapenv:Envelope xmlns:a26mifir="http://www.bafin.de/mvp/a26mifir/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    //      <soapenv:Header>
    //          <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurityutility-1.0.xsd">
    //              <wsse:UsernameToken wsu:Id="UsernameToken44C3662D584567FE6A14672949268541">
    //                  <wsse:Username>karl.meier1234#hg_05_1234567890</wsse:Username>
    //                  <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis200401-wss-username-token-profile-1.0#PasswordText">XXXXXXXXXX</wsse:Password>
    //                  <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis200401-wss-soap-message-security1.0#Base64Binary">+WifMh5kFw/1fHgMahFu7A==</wsse:Nonce>
    //                  <wsu:Created>2016-06-30T13:55:26.852Z</wsu:Created>
    //              </wsse:UsernameToken>
    //          </wsse:Security>
    //      </soapenv:Header>
    //      <soapenv:Body>
    //          <a26mifir:submitDATTRA>
    //              <inDATTRA>
    //                  <a26mifir:dateiname>A26MiFIR_Testfile_001.xml</a26mifir:dateiname>
    //              </inDATTRA>
    //              <kundenreferenz>ClientRef_001</kundenreferenz>
    //              <datei>
    //                  <inc:Include href="cid:139580394822" xmlns:inc="http://www.w3.org/2004/08/xop/include"/>
    //              </datei>
    //          </a26mifir:submitDATTRA>
    //      </soapenv:Body>
    //  </soapenv:Envelope>

    //  ------------------------------------------------------------
    //  We want the top-most header of our request to look like this:

    //  POST https://portal.mvp.bafin.de:444/services/ws/t_a26mifir HTTP/1.1
    //  Content-Encoding: gzip
    //  Accept-Encoding: gzip,deflate
    //  Content-Type: multipart/related; type="application/xop+xml";
    //     start="<rootpart@soapui.org>"; start-info="text/xml"; boundary="----=_Part_3_19706996.1467294979823"
    //  SOAPAction: "http://www.bafin.de/mvp/a26mifir/submitDATTRA"
    //  MIME-Version: 1.0
    //  Transfer-Encoding: chunked
    //  Host: portal.mvp.bafin.de:444
    //  Connection: Keep-Alive
    //  User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

    //  Some header fields are unimportant.  
    //  1) We can omit the User-Agent.
    //  2) Also, the Transfer-Encoding doesn't need to be "chunked".  It shouldn't matter whether it's chunked or non-chunked.
    //  3) We do need the Content-Encoding to be "gzip", because the documentation at https://www.bafin.de/SharedDocs/Downloads/EN/dl_mvp-portal_soap_webservice_a26mifir_en.pdf
    //  explicitly states that it wants a gzip compressed request body.
    //  4) Don't worry about specifying a boundary.  Chilkat will auto-generate a boundary and add it to the Content-Type.
    //  5) If we're sending many requests on the same connection, then set the Connection: Keep-Alive header.  Otherwise, there is no need for it.

    //  Begin specifying header fields for the topmost header:
    CkRestW_AddHeader(rest,L"Content-Type",L"multipart/related; type=\"application/xop+xml\"; start=\"<rootpart@soapui.org>\"; start-info=\"text/xml\"");
    CkRestW_AddHeader(rest,L"Content-Encoding",L"gzip");
    CkRestW_AddHeader(rest,L"Accept-Encoding",L"gzip,deflate");
    CkRestW_AddHeader(rest,L"SOAPAction",L"http://www.bafin.de/mvp/a26mifir/submitDATTRA");
    CkRestW_AddHeader(rest,L"MIME-Version",L"1.0");
    CkRestW_AddHeader(rest,L"Connection",L"Keep-Alive");

    //  ------------------------------------------------------------
    //  Build the header for the 1st sub-part, which will contain the SOAP envelope.
    //  It will look like this:

    //  Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
    //  Content-Transfer-Encoding: 8bit
    //  Content-ID: <rootpart@soapui.org>

    CkRestW_putPartSelector(rest,L"1");
    CkRestW_AddHeader(rest,L"Content-Type",L"application/xop+xml; charset=UTF-8; type=\"text/xml\"");
    CkRestW_AddHeader(rest,L"Content-Transfer-Encoding",L"8bit");
    CkRestW_AddHeader(rest,L"Content-ID",L"<rootpart@soapui.org>");
    CkXmlW_putEmitCompact(soapXml,TRUE);
    CkXmlW_putEmitXmlDecl(soapXml,FALSE);
    CkRestW_SetMultipartBodyString(rest,CkXmlW_getXml(soapXml));

    //  ------------------------------------------------------------
    //  Build the header for the 1st sub-part, which will contain the SOAP envelope.
    //  It will look like this:

    //  Content-Type: application/octet-binary; name=A26MiFIR_Testfile_001.xml
    //  Content-Transfer-Encoding: binary
    //  Content-ID: <139580394822>
    //  Content-Disposition: attachment; name=" A26MiFIR_Testfile_001.xml"; filename="A26MiFIR_Testfile_001.xml"

    CkRestW_putPartSelector(rest,L"2");
    CkRestW_AddHeader(rest,L"Content-Type",L"application/octet-binary; name=A26MiFIR_Testfile_001.xml");
    CkRestW_AddHeader(rest,L"Content-Transfer-Encoding",L"binary");
    CkRestW_AddHeader(rest,L"Content-ID",L"<139580394822>");
    CkRestW_AddHeader(rest,L"Content-Disposition",L"attachment; name=\"A26MiFIR_Testfile_001.xml\"; filename=\"A26MiFIR_Testfile_001.xml\"");

    //  We'll just use a fake attachment XML body for this example
    CkRestW_SetMultipartBodyString(rest,L"<test>blah blah blah</test>");

    //  ------------------------------------------------------------
    //  The request is fully specified.  Now send the POST...

    //  Turn on DebugMode.  This is a mode where no request is sent.  Instead, the request that would've been
    //  sent is recorded and can be retrieved via the GetLastDebugRequest method.
    CkRestW_putDebugMode(rest,TRUE);

    responseBody = CkRestW_fullRequestMultipart(rest,L"POST",L"/services/ws/t_a26mifir");
    if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkXmlW_Dispose(soapXml);
        return;
    }

    //  Because we set DebugMode, no request was actually sent.  Instead, we can examine the exact
    //  request that would've been sent:
    if (CkRestW_getDebugMode(rest) == TRUE) {
        bdRequest = CkBinDataW_Create();
        success = CkRestW_GetLastDebugRequest(rest,bdRequest);
        success = CkBinDataW_WriteFile(bdRequest,L"qa_output/bafin_request.txt");
    }

    wprintf(L"Success.\n");

    //  Clear the REST object for any subsequent requests..
    CkRestW_ClearAllHeaders(rest);
    CkRestW_ClearAllParts(rest);
    CkRestW_putPartSelector(rest,L"");


    CkRestW_Dispose(rest);
    CkXmlW_Dispose(soapXml);
    CkBinDataW_Dispose(bdRequest);

    }