带有附件的ColdFusion SOAP响应

带有附件的ColdFusion SOAP响应,soap,coldfusion,Soap,Coldfusion,我正在使用Coldfusion9与第三方SOAP服务交互,我需要使用该服务发送和接收带有附件的SOAP。通过在HTTP内容周围使用ToString()将SOAP正文转换为可用字符串,我在接收SOAP时没有问题,SOAP可能有也可能没有二进制附件,但是服务要求我也使用附件发送我的响应,这就是我要撤消的地方。我从来没有在ColdFusion中这样做过,我也不确定应该如何将其呈现给原始服务,以便通过ID引用SOAP主体 下面是对带有附件的传入SOAP数据的解析: <cfset soapData

我正在使用Coldfusion9与第三方SOAP服务交互,我需要使用该服务发送和接收带有附件的SOAP。通过在HTTP内容周围使用ToString()将SOAP正文转换为可用字符串,我在接收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#">

#http#u项#:#StructFind(soapData.headers,http#u项)#chr(10)#chr(13)#
请求方法:#soapData.method##chr(10)##chr(13)#
服务器协议:#soapData.protocol##chr(10)##chr(13)#
http#u内容--#chr(10)##chr(13)#
#toString(soapData.content)#
现在,我将响应表示为一个完整的SOAP XML响应,其中包含作为内联XML的主体以及所需的状态代码(见下文)


00
#strResponse#
上述响应引发了一个错误,因为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--
HTTP/1.1200正常
日期:2010年4月1日星期四09:30:25 GMT
服务器:Jetty/5.1.4(Windows XP/5.1 x86 java/1.5.015
内容类型:多部分/相关;边界=soaptestserver;Type=“text/xml”;start=“”
SOAPAction:“
内容长度:796
连接:关闭
--soaptestserver
内容ID:
内容传输编码:8比特
内容类型:text/xml;字符集=utf-8
内容长度:442
--soaptestserver
SOAP接口
www.travelsolutions.com 123
旅行解决方案在线V14.0外部系统集成
内容ID:
内容传输编码:8比特
内容类型:text/xml;字符集=utf-8
内容长度:65
00
--soaptestserver--

如果有任何帮助,我将不胜感激,因为我在这方面真的遇到了麻烦。谢谢!

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

如果您选择这样做,您要查看的Java库是。您还需要了解服务调用是否必须使用MTOM


很抱歉,这不是一个直接的解决方案,但这正是我以前使用CF的一些版本所要做的。

每当我与SOAP服务交互时,我通常都会使用类似的方法。它通常是有效的。请注意,我在其中有一些占位符文本,您需要用第三方提供的适当值替换这些文本r

<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> 

00

这不是我玩过的东西。看起来您正在尝试将请求构建为字符串;我猜您遇到了格式错误的XML或命名空间问题。我将使用ColdFusion的XML支持和
AddSOAPRequestHeader()来代替字符串构建
function:该链接有一个发送和使用SOAP的示例。另一端的开发人员基本上说,他们的日志显示我试图直接在SOAP主体内发送响应,而实际上我需要将其作为附件包含,否则它将不起作用。所以“00”响应行需要从主SOAP响应中引用,这是我在CF中不确定的。它几乎像SOAP请求中的超链接引用。他们为什么要这样做是另一个问题,因为这似乎过于复杂:SUnderstand。我建议研究ColdFusion如何允许您做一些事情沿着以下几行进行搜索:
ws=createObject('webservice','http://domain/file.ext?wsdl“)
然后可以执行
ws.method(参数=值)
calls。我的第一个链接演示了这一点。尝试查看SoapUI,它是一个很好的工具,可以帮助解决问题,无论是您的代码还是其他问题。您的问题获得了相当多的流量,如果您找到答案,您应该将其发布以帮助社区。祝您好运。您好,Chad,我们团队中目前没有java资源,因此此选项这会有点棘手,需要外部干预,我真的希望能有一个明确的是/否答案来纯粹使用CF9来实现这个SOAP响应,这似乎很有可能,但听起来你使用的是旧版本的CF,当时可能不受支持。为延迟响应道歉这是一个漫长的过程自从我跳进这样的房子里已经有一段时间了!
<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>