Sample code for 30+ languages & platforms
PowerBuilder

Yet Another SOAP MTOM POST Example

See more HTTP Misc Examples

Demonstrates how to sending a SOAP request with an MTOM/XOP attachment...

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Xml
oleobject loo_Req
long li_UseTls
oleobject loo_Resp
oleobject loo_XmlResponse

li_Success = 0

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  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>

loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")

loo_Xml.Tag = "soapenv:Envelope"
loo_Xml.AddAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/")
loo_Xml.AddAttribute("xmlns:imp","http://www.yourdomain.it/ImportMultiploWorkflowPAWS/")
loo_Xml.UpdateChildContent("soapenv:Header","")
loo_Xml.UpdateChildContent("soapenv:Body|imp:InputImportMultiploWorkflowPA|usernameEis","MyUsername")
loo_Xml.UpdateChildContent("soapenv:Body|imp:InputImportMultiploWorkflowPA|passwordEis","MyPassword")
loo_Xml.UpdateChildContent("soapenv:Body|imp:InputImportMultiploWorkflowPA|postazioneEis","COSO00")
loo_Xml.UpdateChildContent("soapenv:Body|imp:InputImportMultiploWorkflowPA|istitutoEis","COSO")
loo_Xml.UpdateChildContent("soapenv:Body|imp:InputImportMultiploWorkflowPA|codiceAzienda","COSO0000")
loo_Xml.UpdateAttrAt("soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZip|inc:Include",1,"href","cid:780931946797")
loo_Xml.UpdateAttrAt("soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZip|inc:Include",1,"xmlns:inc","http://www.w3.org/2004/08/xop/include")
loo_Xml.UpdateChildContent("soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZipName","IT04769180151_00044.zip")
loo_Xml.UpdateChildContent("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)

loo_Req = create oleobject
li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest")

loo_Req.HttpVerb = "POST"
loo_Req.Path = "/http-router-softwarehubsystem/webservices/importMultiploWorkflowPA"
loo_Req.ContentType = "multipart/related; type=~"application/xop+xml~"; start=~"<rootpart@soapui.org>~"; start-info=~"text/xml~""
loo_Req.AddHeader("SOAPAction","~"http://www.yourdomain.it/ImportMultiploWorkflowPAWS/importMultiploWorkflowPA~"")
loo_Req.AddHeader("Accept-Encoding","gzip,deflate")
loo_Req.AddHeader("Mime-Version","1.0")
loo_Req.AddHeader("Connection","Keep-Alive")
loo_Req.AddHeader("User-Agent","Apache-HttpClient/4.1.1 (java 1.5)")

//  Add the XML content for the 1st MIME sub-part.
loo_Xml.EmitXmlDecl = 0
loo_Xml.EmitCompact = 0
li_Success = loo_Req.AddStringForUpload2("","",loo_Xml.GetXml(),"utf-8","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.
li_Success = loo_Req.AddSubHeader(0,"Content-Transfer-Encoding","8bit")
li_Success = loo_Req.AddSubHeader(0,"Content-ID","<rootpart@soapui.org>")

//  Add a reference to the local file for the file data for the 2nd MIME sub-part.
li_Success = loo_Req.AddFileForUpload2("","qa_data/zips/helloWorld.zip","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.
li_Success = loo_Req.AddSubHeader(1,"Content-Transfer-Encoding","binary")
li_Success = loo_Req.AddSubHeader(1,"Content-ID","<IT04769180151_00044.zip>")
li_Success = loo_Req.AddSubHeader(1,"Content-Disposition","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.
loo_Http.SessionLogFilename = "qa_output/mtom_sessionLog.txt"

li_UseTls = 0
//  Note: Please don't run this example without changing the domain to your own domain...
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpSReq("www.yourdomain.it",80,li_UseTls,loo_Req,loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Xml
    destroy loo_Req
    destroy loo_Resp
    return
end if

loo_XmlResponse = create oleobject
li_rc = loo_XmlResponse.ConnectToNewObject("Chilkat.Xml")

li_Success = loo_XmlResponse.LoadXml(loo_Resp.BodyStr)
//  println xmlResponse.GetXml();

Write-Debug "OK."


destroy loo_Http
destroy loo_Xml
destroy loo_Req
destroy loo_Resp
destroy loo_XmlResponse