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
(Swift 2) BaFin MVP Portal SOAP Web Service MTOMDemonstrate 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 For more information, see https://www.bafin.de/SharedDocs/Downloads/EN/dl_mvp-portal_soap_webservice_a26mifir_en.pdf
func chilkatTest() { // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. let rest = CkoRest() // Connect to portal.mvp.bafin.de:444 var bTls: Bool = true var port: Int = 444 var bAutoReconnect: Bool = true var success: Bool = rest.Connect("portal.mvp.bafin.de", port: port, tls: bTls, autoReconnect: bAutoReconnect) if success != true { print("\(rest.LastErrorText)") 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 let soapXml = CkoXml() soapXml.Tag = "soapenv:Envelope" soapXml.AddAttribute("xmlns:a26mifir", value: "http://www.bafin.de/mvp/a26mifir/") soapXml.AddAttribute("xmlns:soapenv", value: "http://schemas.xmlsoap.org/soap/envelope/") soapXml.UpdateAttrAt("soapenv:Header|wsse:Security", autoCreate: true, attrName: "soapenv:mustUnderstand", attrValue: "1") soapXml.UpdateAttrAt("soapenv:Header|wsse:Security", autoCreate: true, attrName: "xmlns:wsse", attrValue: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd") soapXml.UpdateAttrAt("soapenv:Header|wsse:Security", autoCreate: true, attrName: "xmlns:wsu", attrValue: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurityutility-1.0.xsd") soapXml.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:UsernameToken", autoCreate: true, attrName: "wsu:Id", attrValue: "UsernameToken44C3662D584567FE6A14672949268541") soapXml.UpdateChildContent("soapenv:Header|wsse:Security|wsse:UsernameToken|wsse:Username", value: "karl.meier1234#hg_05_1234567890") soapXml.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:UsernameToken|wsse:Password", autoCreate: true, attrName: "Type", attrValue: "http://docs.oasis-open.org/wss/2004/01/oasis200401-wss-username-token-profile-1.0#PasswordText") soapXml.UpdateChildContent("soapenv:Header|wsse:Security|wsse:UsernameToken|wsse:Password", value: "XXXXXXXXXX") soapXml.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:UsernameToken|wsse:Nonce", autoCreate: true, attrName: "EncodingType", attrValue: "http://docs.oasis-open.org/wss/2004/01/oasis200401-wss-soap-message-security1.0#Base64Binary") soapXml.UpdateChildContent("soapenv:Header|wsse:Security|wsse:UsernameToken|wsse:Nonce", value: "+WifMh5kFw/1fHgMahFu7A==") soapXml.UpdateChildContent("soapenv:Header|wsse:Security|wsse:UsernameToken|wsu:Created", value: "2016-06-30T13:55:26.852Z") soapXml.UpdateChildContent("soapenv:Body|a26mifir:submitDATTRA|inDATTRA|a26mifir:dateiname", value: "A26MiFIR_Testfile_001.xml") soapXml.UpdateChildContent("soapenv:Body|a26mifir:submitDATTRA|kundenreferenz", value: "ClientRef_001") soapXml.UpdateAttrAt("soapenv:Body|a26mifir:submitDATTRA|datei|inc:Include", autoCreate: true, attrName: "href", attrValue: "cid:139580394822") soapXml.UpdateAttrAt("soapenv:Body|a26mifir:submitDATTRA|datei|inc:Include", autoCreate: true, attrName: "xmlns:inc", attrValue: "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: rest.AddHeader("Content-Type", value: "multipart/related; type=\"application/xop+xml\"; start=\"<rootpart@soapui.org>\"; start-info=\"text/xml\"") rest.AddHeader("Content-Encoding", value: "gzip") rest.AddHeader("Accept-Encoding", value: "gzip,deflate") rest.AddHeader("SOAPAction", value: "http://www.bafin.de/mvp/a26mifir/submitDATTRA") rest.AddHeader("MIME-Version", value: "1.0") rest.AddHeader("Connection", value: "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> rest.PartSelector = "1" rest.AddHeader("Content-Type", value: "application/xop+xml; charset=UTF-8; type=\"text/xml\"") rest.AddHeader("Content-Transfer-Encoding", value: "8bit") rest.AddHeader("Content-ID", value: "<rootpart@soapui.org>") soapXml.EmitCompact = true soapXml.EmitXmlDecl = false rest.SetMultipartBodyString(soapXml.GetXml()) // ------------------------------------------------------------ // 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" rest.PartSelector = "2" rest.AddHeader("Content-Type", value: "application/octet-binary; name=A26MiFIR_Testfile_001.xml") rest.AddHeader("Content-Transfer-Encoding", value: "binary") rest.AddHeader("Content-ID", value: "<139580394822>") rest.AddHeader("Content-Disposition", value: "attachment; name=\"A26MiFIR_Testfile_001.xml\"; filename=\"A26MiFIR_Testfile_001.xml\"") // We'll just use a fake attachment XML body for this example rest.SetMultipartBodyString("<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. rest.DebugMode = true var responseBody: String? = rest.FullRequestMultipart("POST", uriPath: "/services/ws/t_a26mifir") if rest.LastMethodSuccess != true { print("\(rest.LastErrorText)") return } // Because we set DebugMode, no request was actually sent. Instead, we can examine the exact // request that would've been sent: if rest.DebugMode == true { let bdRequest = CkoBinData() success = rest.GetLastDebugRequest(bdRequest) success = bdRequest.WriteFile("qa_output/bafin_request.txt") } print("Success.") // Clear the REST object for any subsequent requests.. rest.ClearAllHeaders() rest.ClearAllParts() rest.PartSelector = "" } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.