English 中文(简体)
带附件的ColdFusion SOAP响应
原标题:ColdFusion SOAP response with attachments

我正在使用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--

任何帮助都将不胜感激,因为我真的在这件事上撞到了墙上。谢谢

问题回答

我已经有一段时间没有和ColdFusion合作了。我记得最后一次,它没有提供发送SOAP附件的工具。我通过编写自定义CFX标记,Java为我做了这件事。整个SOAP调用都需要通过该标记。

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

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

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

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




相关问题
Python SOAP server / client

I have a problem with Python and SOAP. I need to create a web service based on SOAP in Python. I read that I can use libraries like soaplib, suds and ZSI. I created a Hello World web service with ...

HTTP POST and complex structures

I m trying to send a complex HTTP POST request to a web service. The web service was created using VS2008, in which you can set VS to create HTTP POST and GET interfaces alongside the SOAP one. Now ...

XML-RPC Standard and XML Data Type

I was looking at XML-RPC for a project. And correct me if I m wrong, but it seems like XML-RPC has no XML datatype. Are you supposed to pass as a string? or something else? Am I missing something? ...

Most appropriate API for URL shortening service

I ve just finished an online service for shortening URLs (in php5 with Zend Framework); you can enter an URL and you get an short URL (like tinyurl and such sites). I m thinking about the API for ...

What is the best solution for creating a SOAP Server in PHP?

I need some advice on which library is the best choice when it comes to creating SOAP servers (and eventually SOAP clients) in PHP. I know there is built-in functions for this, but is that really the ...

Logging all Soap request and responses in PHP

Does anyone know how to log all request and responses with the builtin SoapClient in PHP? I could in fact manually log everything with SoapClient::__getLastRequest() and SoapClient::__getLastResponse()...

热门标签