我正在使用Coldfusion9与第三方SOAP服务进行交互,我需要使用该服务发送和接收带有附件的SOAP。通过在HTTP内容周围使用ToString()将SOAP正文转换为可用的字符串,我在接收可能有二进制附件也可能没有二进制附件的SOAP时没有问题,但是该服务要求我也使用附件发送回响应,这就是我要撤消的地方。我从来没有在ColdFusion中这样做过,我也不确定应该如何将其呈现给始发服务,以便通过ID引用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#">
现在,我将响应呈现为一个完整的SOAP XML响应,其中包含内联XML的主体和所需的STATUSCODE(见下文)。
<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--
任何帮助都将不胜感激,因为我真的在这件事上撞到了墙上。谢谢