Note that there are some explanatory texts on larger screens.

plurals
  1. POColdFusion SOAP response with attachments
    text
    copied!<p>I am using Coldfusion9 to interact with a 3rd party SOAP service with which I need to both send and receive SOAP with attachments. I am having no issue in receiving the SOAP which may or may not have binary attachments by using ToString() around the HTTP content to convert the SOAP Body into a usable string, however the service requires that I send my response back using attachments as well which is where I am coming undone. I've just never done this in ColdFusion and i'm not exactly sure how I should be presenting this to the originating service so that the SOAP body is referenced via an ID.</p> <p>Below is the parsing of the incoming SOAP data with attachments:</p> <pre><code>&lt;cfset soapData = GetHttpRequestData()&gt; &lt;!--- Loop over the HTTP headers and dump the SOAP content into a variable ---&gt; &lt;cfsavecontent variable="soapContent"&gt; &lt;cfoutput&gt; &lt;cfloop collection = #soapData.headers# item = "http_item"&gt; #http_item#: #StructFind(soapData.headers, http_item)# #chr(10)##chr(13)# &lt;/cfloop&gt; request_method: #soapData.method# #chr(10)##chr(13)# server_protocol: #soapData.protocol# #chr(10)##chr(13)# http_content --- #chr(10)##chr(13)# #toString(soapData.content)# &lt;/cfoutput&gt; &lt;/cfsavecontent&gt; &lt;!--- Save file to flat file ---&gt; &lt;cffile action = "write" file = "#expandPath('../')#logs/#dateFormat(now(),'dd-mm-yyyy')#_#timeFormat(now(),'HHmmss')#.txt" output = "#soapContent#"&gt; </code></pre> <p>Now I am currently presenting the response as a full SOAP XML response containing the body as inline XML with the required STATUSCODE (see below). </p> <pre><code>&lt;cfsavecontent variable="strResponse"&gt; &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;SOAP-ENV:Envelope xmlns:SOAPENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"&gt; &lt;SOAPENV:Body&gt; &lt;ns1:processResponse xmlns:ns1="urn:TripFlow" SOAPENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt; &lt;STATUSLVL&gt;00&lt;/STATUSLVL&gt; &lt;/ns1:processResponse&gt; &lt;/SOAP-ENV:Body&gt; &lt;/SOAPENV:Envelope&gt; &lt;/cfsavecontent&gt; &lt;!--- Strip all whitespace between tags ---&gt; &lt;cfset strResponse = trim(ReReplaceNoCase(strResponse,'(&gt;[\s]*&lt;)','&gt;&lt;','ALL'))&gt; &lt;!--- Output the XML response to the soap service ---&gt; &lt;cfoutput&gt;#strResponse#&lt;/cfoutput&gt; </code></pre> <p>The above response is throwing an error because the SOAP service requires the response to be sent referencing the body message as an attachment exactly like follows from the documentation:</p> <pre><code>HTTP/1.1 200 OK Date: Thu, 01 Apr 2010 09:30:25 GMT Server: Jetty/5.1.4 (Windows XP/5.1 x86 java/1.5.0_15 Content-Type: multipart/related; boundary=soaptestserver; type="text/xml"; start="&lt;theenvelope&gt;" SOAPAction: "" Content-Length: 796 Connection: close --soaptestserver Content-ID: &lt;theenvelope&gt; Content-Transfer-Encoding: 8bit Content-Type: text/xml; charset=utf-8 Content-Length: 442 &lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;SOAP-ENV:Envelope xmlns:SOAPENV=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"&gt;&lt;SOAPENV: Body&gt;&lt;ns1:processResponse xmlns:ns1="urn:TripFlow" SOAPENV: encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;message href="cid:thecontentmessage"/&gt;&lt;/ns1:processResponse&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAPENV: Envelope&gt; --soaptestserver SOAP Interface www.travelsolutions.com 123 travel solutions online V14.0 External System Integration Content-ID: &lt;thecontentmessage&gt; Content-Transfer-Encoding: 8bit Content-Type: text/xml; charset=utf-8 Content-Length: 65 &lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;STATUSLVL&gt;00&lt;/STATUSLVL&gt; --soaptestserver-- </code></pre> <p>Any help would be greatly appreciate as i'm really hitting my head up against a wall on this one. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload