【发布时间】:2012-09-06 23:41:25
【问题描述】:
我正在使用 Coldfusion9 与第 3 方 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--
任何帮助都将不胜感激,因为我真的把头撞在墙上了。谢谢!
【问题讨论】:
-
不是我玩过的东西。看起来您正在尝试将请求构建为字符串;我猜您遇到了格式错误的 XML 或命名空间问题。我会使用 ColdFusion 的 XML 支持和
AddSOAPRequestHeader()函数而不是字符串构建:livedocs.adobe.com/coldfusion/8/htmldocs/… 该链接有一个发送和使用 SOAP 的示例。 -
好吧,另一端的开发人员基本上说他们的日志显示我正在尝试直接在 SOAP 正文中发送响应,而实际上我需要将其作为附件包含在内,否则它将不起作用.因此,需要从主 SOAP 响应中引用“
00 ”响应行,这就是我不确定的在 CF 中。它几乎看起来像是 SOAP 请求中的超链接引用。为什么他们想要这种方式完全是另一个问题,因为这似乎使事情过于复杂:S -
明白。我建议研究 ColdFusion 如何让您按照以下方式进行操作:
ws = createObject('webservice', 'http://domain/file.ext?wsdl'),然后您可以在其中进行ws.method(argument=value)调用。我的第一个链接证明了这一点。 -
尝试研究 SoapUI,它是一个很好的工具,可以帮助解决您的代码或其他问题。
-
您的问题获得了相当多的流量,如果您找到了答案,您应该发布它以帮助社区。祝你好运。
标签: soap coldfusion