我正在使用Coldfusion9與第三方SOAP服務交互,我需要使用它發送和接收帶有附件的SOAP。通過在HTTP內容周圍使用ToString()將SOAP Body轉換爲可用的字符串,我在接收可能具有或可能不具有二進制附件的SOAP時沒有問題,但是該服務要求我使用附件將回復發送回去這是我未來的地方。我從來沒有在ColdFusion中做過這件事,我也不確定我應該如何將它展示給原始服務,以便通過一個ID引用SOAP體。帶附件的ColdFusion SOAP響應
下面是傳入的SOAP數據的帶附件解析:
<cfset soapData = GetHttpRequestData()>
<!--- Loop over the HTTP headers and dump the SOAP content into a variable --->
<cfsavecontent variable="soapContent">
<cfoutput>
<cfloop collection = #soapData.headers# item = "http_item">
#http_item#: #StructFind(soapData.headers, http_item)# #chr(10)##chr(13)#
</cfloop>
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)#
</cfoutput>
</cfsavecontent>
<!--- Save file to flat file --->
<cffile action = "write"
file = "#expandPath('../')#logs/#dateFormat(now(),'dd-mm-yyyy')#_#timeFormat(now(),'HHmmss')#.txt"
output = "#soapContent#">
現在我目前呈現所述響應作爲包含體爲內聯XML具有所需的StatusCode全SOAP的XML響應(見下文) 。
<cfsavecontent variable="strResponse">
<?xml version="1.0" encoding="UTF-8"?>
<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">
<SOAPENV:Body>
<ns1:processResponse xmlns:ns1="urn:TripFlow" SOAPENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<STATUSLVL>00</STATUSLVL>
</ns1:processResponse>
</SOAP-ENV:Body>
</SOAPENV:Envelope>
</cfsavecontent>
<!--- Strip all whitespace between tags --->
<cfset strResponse = trim(ReReplaceNoCase(strResponse,'(>[\s]*<)','><','ALL'))>
<!--- Output the XML response to the soap service --->
<cfoutput>#strResponse#</cfoutput>
因爲SOAP服務需要響應被髮送引用體郵件作爲附件酷似上述響應引發錯誤如下從文檔:
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="<theenvelope>"
SOAPAction: ""
Content-Length: 796
Connection: close
--soaptestserver
Content-ID: <theenvelope>
Content-Transfer-Encoding: 8bit
Content-Type: text/xml; charset=utf-8
Content-Length: 442
<?xml version="1.0" encoding="UTF-8"?><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"><SOAPENV:
Body><ns1:processResponse xmlns:ns1="urn:TripFlow" SOAPENV:
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><message
href="cid:thecontentmessage"/></ns1:processResponse></SOAP-ENV:Body></SOAPENV:
Envelope>
--soaptestserver
SOAP Interface
www.travelsolutions.com 123
travel solutions online V14.0 External System Integration
Content-ID: <thecontentmessage>
Content-Transfer-Encoding: 8bit
Content-Type: text/xml; charset=utf-8
Content-Length: 65
<?xml version="1.0" encoding="UTF-8"?><STATUSLVL>00</STATUSLVL>
--soaptestserver--
任何幫助將是大大欣賞,因爲我真的把我的頭靠在這個牆上。謝謝!
不是我玩過的東西。看起來你想要建立一個字符串的請求;我猜你正在碰到格式不正確的XML或命名空間問題。我不使用字符串構建,而是使用ColdFusion的XML支持和`AddSOAPRequestHeader()`函數:http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_a-b_03.html#5050827該鏈接有一個發送和使用SOAP的例子。 – orangepips 2011-02-14 02:25:59
那麼在另一端的開發人員已經基本上說他們的日誌顯示我試圖直接在SOAP身體內發送響應,實際上我需要將它作爲附件包含或它不起作用。因此,需要從主SOAP響應中引用「<?xml version =」1.0「encoding =」UTF-8「?> 」響應行「,這是我在CF中不確定的。它幾乎看起來像SOAP請求中的超鏈接引用。爲什麼他們想要這樣做是另一個問題,因爲這似乎是過於複雜的事情:S – 2011-02-14 04:58:07