DataFlex
DataFlex
Yet Another SOAP MTOM POST Example
See more HTTP Misc Examples
Demonstrates how to sending a SOAP request with an MTOM/XOP attachment...Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Handle hoXml
Variant vReq
Handle hoReq
Boolean iUseTls
Variant vResp
Handle hoResp
Handle hoXmlResponse
String sTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// 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>
Get Create (RefClass(cComChilkatXml)) To hoXml
If (Not(IsComObjectCreated(hoXml))) Begin
Send CreateComObject of hoXml
End
Set ComTag Of hoXml To "soapenv:Envelope"
Get ComAddAttribute Of hoXml "xmlns:soapenv" "http://schemas.xmlsoap.org/soap/envelope/" To iSuccess
Get ComAddAttribute Of hoXml "xmlns:imp" "http://www.yourdomain.it/ImportMultiploWorkflowPAWS/" To iSuccess
Send ComUpdateChildContent To hoXml "soapenv:Header" ""
Send ComUpdateChildContent To hoXml "soapenv:Body|imp:InputImportMultiploWorkflowPA|usernameEis" "MyUsername"
Send ComUpdateChildContent To hoXml "soapenv:Body|imp:InputImportMultiploWorkflowPA|passwordEis" "MyPassword"
Send ComUpdateChildContent To hoXml "soapenv:Body|imp:InputImportMultiploWorkflowPA|postazioneEis" "COSO00"
Send ComUpdateChildContent To hoXml "soapenv:Body|imp:InputImportMultiploWorkflowPA|istitutoEis" "COSO"
Send ComUpdateChildContent To hoXml "soapenv:Body|imp:InputImportMultiploWorkflowPA|codiceAzienda" "COSO0000"
Get ComUpdateAttrAt Of hoXml "soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZip|inc:Include" True "href" "cid:780931946797" To iSuccess
Get ComUpdateAttrAt Of hoXml "soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZip|inc:Include" True "xmlns:inc" "http://www.w3.org/2004/08/xop/include" To iSuccess
Send ComUpdateChildContent To hoXml "soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZipName" "IT04769180151_00044.zip"
Send ComUpdateChildContent To hoXml "soapenv:Body|imp:InputImportMultiploWorkflowPA|workflow" "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)
Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
If (Not(IsComObjectCreated(hoReq))) Begin
Send CreateComObject of hoReq
End
Set ComHttpVerb Of hoReq To "POST"
Set ComPath Of hoReq To "/http-router-softwarehubsystem/webservices/importMultiploWorkflowPA"
Set ComContentType Of hoReq To 'multipart/related; type="application/xop+xml"; start="<rootpart@soapui.org>"; start-info="text/xml"'
Send ComAddHeader To hoReq "SOAPAction" '"http://www.yourdomain.it/ImportMultiploWorkflowPAWS/importMultiploWorkflowPA"'
Send ComAddHeader To hoReq "Accept-Encoding" "gzip,deflate"
Send ComAddHeader To hoReq "Mime-Version" "1.0"
Send ComAddHeader To hoReq "Connection" "Keep-Alive"
Send ComAddHeader To hoReq "User-Agent" "Apache-HttpClient/4.1.1 (java 1.5)"
// Add the XML content for the 1st MIME sub-part.
Set ComEmitXmlDecl Of hoXml To False
Set ComEmitCompact Of hoXml To False
Get ComGetXml Of hoXml To sTemp1
Get ComAddStringForUpload2 Of hoReq "" "" sTemp1 "utf-8" 'application/xop+xml; charset=UTF-8; type="text/xml"' To iSuccess
// 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.
Get ComAddSubHeader Of hoReq 0 "Content-Transfer-Encoding" "8bit" To iSuccess
Get ComAddSubHeader Of hoReq 0 "Content-ID" "<rootpart@soapui.org>" To iSuccess
// Add a reference to the local file for the file data for the 2nd MIME sub-part.
Get ComAddFileForUpload2 Of hoReq "" "qa_data/zips/helloWorld.zip" "application/zip; name=IT04769180151_00044.zip" To iSuccess
// 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.
Get ComAddSubHeader Of hoReq 1 "Content-Transfer-Encoding" "binary" To iSuccess
Get ComAddSubHeader Of hoReq 1 "Content-ID" "<IT04769180151_00044.zip>" To iSuccess
Get ComAddSubHeader Of hoReq 1 "Content-Disposition" 'attachment; name="IT04769180151_00044.zip"; filename="IT04769180151_00044.zip"' To iSuccess
// Keep a session log so we can examine the exact request/response.
// Remove this line when finished with debugging.
Set ComSessionLogFilename Of hoHttp To "qa_output/mtom_sessionLog.txt"
Move False To iUseTls
// Note: Please don't run this example without changing the domain to your own domain...
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoReq to vReq
Get pvComObject of hoResp to vResp
Get ComHttpSReq Of hoHttp "www.yourdomain.it" 80 iUseTls vReq vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatXml)) To hoXmlResponse
If (Not(IsComObjectCreated(hoXmlResponse))) Begin
Send CreateComObject of hoXmlResponse
End
Get ComBodyStr Of hoResp To sTemp1
Get ComLoadXml Of hoXmlResponse sTemp1 To iSuccess
// println xmlResponse.GetXml();
Showln "OK."
End_Procedure