2013-07-31 68 views
0

我是ColdFusion的新手,需要編寫代碼來使用基於SOAP的Web服務。消費具有複雜類型的SOAP Web服務

任何用於消費具有複雜類型的基於SOAP的Web服務的鏈接/指針/示例都將有所幫助。

當我在ColdFusion中編寫消費以下Web服務的代碼時,應該如何處理操作名稱,輸入消息和複雜類型?只需要一些指針即可開始。

XSD是一樣的東西:

<!-- S Request --> 
    <xs:complexType name="SRequestHeader"> 
    + <xs:sequence> 
    + <xs:element name="sID" minOccurs="1" maxOccurs="1"> </xs:element> 
    + <xs:element name="orderNumber" minOccurs="1" maxOccurs="1"> </xs:element> 
    + <xs:element name="dateCreated" minOccurs="1" maxOccurs="1"> </xs:element> 
    </xs:complexType> 
    - <xs:complexType name="SOrderLine"> 
    - <xs:sequence> 
    - <xs:element name="lineNumber" minOccurs="1" maxOccurs="1"> </xs:element> 
    - <xs:element name="recordType" minOccurs="1" maxOccurs="1"> </xs:element> 
    - <xs:element name="dueDate" minOccurs="1" type="xs:dateTime" />  
    </xs:complexType> 
...... 

WSDL有:

<WL:portType name="SPortType"> 
- <WL:operation name="newOrder"> 
    <WL:input message="WL:newOrderRequest" name="newOrderRequest" />  
    <WL:output> message="W:newOrderResponse" name="newOrderResponse" />  
    <WL:fault> message="WL:WSException" name="WSException" />  
    </WL:operation> 

我使用的是這樣的:

<soapenv:Body>  
    <newOrder> 
    <soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
     <sor:newOrderRequest> 
     <sor:SOrderRequest> 
      <sor:sID>S123</sor:sID> .... 

最後...

<cfhttp url="http://xxxx:123/YYY/SService" method="post" timeout="118"   
     throwonerror="yes"> 
    <cfhttpparam type="header" name="content-type" value="text/xml"> 
    <cfhttpparam type="header" name="SOAPAction" value=""> 
    <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> 

獲取有關該行500內部服務器錯誤

<cfhttpparam type="xml" name="message" value="#trim(soap)#"> 
+0

指針編號1 - 您可能需要創建一個對象。有一個標籤,和一個函數CreateObject(),可以讓你做到這一點。谷歌每個並決定你想使用哪一個。我更喜歡後者。 –

+0

@DanBracuk我使用類似於: \t \t S123 .... – user2286338

回答

2

您還沒有共享完整的代碼等等一些必須做出一些假設。

本Nadel有關於這個話題的精彩寫作。您應該首先閱讀:Making SOAP Web Service Requests With ColdFusion And CFHTTP

每當我與SOAP服務交互時,通常最終會使用類似於以下內容的內容。它與您共享的代碼片段非常相似,但您在發出<cfhttp>請求之前沒有顯示(包括其他內容)<cfsavecontent>標記中的內容以將XML存儲在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:newOrder xmlns:ns1="urn:TripFlow" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
     <sID>001</sID> 
     <orderNumber>12345</orderNumber> 
     <dateCreated>07/31/2013</dateCreated> 
     </ns1:newOrder> 
    </soapenv:Body> 
</soapenv:Envelope> 
</cfsavecontent> 

<!--- Invoke web service to send message---> 
<cfhttp url="http://xxxx:123/YYY/SService" method="post" timeout="10"> 
<cfhttpparam type="header" name="content-type" value="text/xml" /> 
<cfhttpparam type="header" name="SOAPAction" value="""SService-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> 

使用web服務時另一個非常寶貴的工具是soapUI。這肯定也是你的工具包的一部分。您可以使用soapUI構建您的請求並檢查響應。一旦你使用soapUI,你可以將你的請求複製到你的ColdFusion代碼中。

+0

嗨,我使用..just像u必須添加的確切的代碼。但得到500內部服務器錯誤。任何想法可能會出錯? – user2286338

+0

您是否在響應中或從發出請求的ColdFusion服務器獲得了500錯誤?嘗試使用SoapUI進行SOAP請求,看看是否有效。 ColdFusion記錄有關錯誤的更多詳細信息(如果它正在服務器上生成)。 –

+0

完美地工作。謝謝! –

0

Thanks @ Miguel-F。最後使用SOAPUI並瞭解發生了什麼問題。

已設置參數throwonerror =「是」。由於此ParseException將進入錯誤塊,而不是在代碼中捕獲。

在設置throwonerror =「No」時,代碼終於開始工作並讀取響應標籤。

+0

我發現SoapUI(和其他類似的工具)在worki時非常寶貴與網絡服務。真高興你做到了。 –