【问题标题】:ColdFusion SOAP response with attachments带有附件的 ColdFusion SOAP 响应
【发布时间】: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


【解决方案1】:

我已经有一段时间没有使用 ColdFusion 了。我记得的最后一个,它没有提供用于发送 SOAP 附件的工具。我通过用 Java 编写 custom CFX 标记解决了这个问题,它为我做了这件事。整个 SOAP 调用都需要通过标签。

如果您选择这样做,您想要查看的 Java 库是 javax-ws。您还需要确定服务调用是否必须使用 MTOM。

对不起,这不是一个直接的解决方案,但这是我在几个版本之前对 CF 所做的。

【讨论】:

  • 嗨,Chad,我们目前在团队中没有 Java 资源,所以这个选项有点棘手,需要外部干预,我真的希望能得到一个明确的是/否答案来纯粹使用 CF9实现此 SOAP 响应,这似乎很接近可能,但听起来您使用的是旧版本的 CF,并且当时可能不支持它。
  • 抱歉,我的年假已经很长了,因为我回到了 SO!
【解决方案2】:

每当我与 SOAP 服务交互时,我通常最终都会使用类似的东西。它通常有效。请注意,我在其中有一些占位符文本,您需要将其替换为适合您的 3rd 方提供商的值。

<cfsavecontent variable="soap">
<?xml version="1.0" encoding="UTF-8" ?> 
<soapenv: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:Header/>
   <soapenv:Body>
      <ns1:processResponse xmlns:ns1="urn:TripFlow" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <statuslvl>00</statuslvl>
      </ns1:processResponse>
   </soapenv:Body>
</soapenv:Envelope>
</cfsavecontent>

<!--- Invoke web service to send message--->
<cfhttp url="http://3rd-party-url-here" method="post" timeout="10">
<cfhttpparam type="header" name="content-type" value="text/xml" />
<cfhttpparam type="header" name="SOAPAction" value="""3rd-party-method-name-here""" />
<!---<cfhttpparam type="header" name="accept-encoding" value="no-compression" />  sometimes this is needed --->
<cfhttpparam type="header" name="content-length" value="#len(soap)#" />
<cfhttpparam type="header" name="charset" value="utf-8" />
<cfhttpparam type="xml" name="message" value="#trim(soap)#" />
</cfhttp> 

【讨论】:

    猜你喜欢
    • 2011-07-17
    • 2012-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 2010-10-23
    相关资源
    最近更新 更多