2010-12-09 18 views
2

我一直是一個cf開發人員11年,但不好意思說我沒有做任何實質性的web服務。如何形成一個cfhttp調用來使用自定義的webservice API

如何形成一個cfhttp調用來使用供應商提供的以下webservice API?

SOAP 1.2請求:

POST /Portal/internet.asmx HTTP/1.1 
Host: 192.168.222.240 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <Usage xmlns="http://portal/internet.asmx"> 
     <SessionID>string</SessionID> 
     <CustomerCode>int</CustomerCode> 
     <FullUserName>string</FullUserName> 
     <StartDate>dateTime</StartDate> 
     <EndDate>dateTime</EndDate> 
    </Usage> 
    </soap12:Body> 
</soap12:Envelope> 
HTTP/1.1 200 OK 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

SOAP 1.2響應:

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <UsageResponse xmlns="http://portal/internet.asmx"> 
     <UsageResult> 
     <xsd:schema>schema</xsd:schema>xml</UsageResult> 
    </UsageResponse> 
    </soap12:Body> 
</soap12:Envelope> 

我想此刻(我知道CFINVOKE和CreateObject)做手工。我從Ben Nadel博客提出以下內容,但是我收到了「連接失敗」錯誤。我想我只是需要有人來檢查代碼中是否存在明顯的缺陷,然後再查看它是否真正與連接/授權相關。

<cfsavecontent variable="soapBody"> 
<cfoutput> 
    <?xml version="1.0" encoding="utf-8"?> 
    <soap:Envelope 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
      <soap:Body> 
      <Usage xmlns="http://portal/internet.asmx"> 
       <SessionID>F7B3B3FB-DE35-45CB-A785-8229E91FAEC9</SessionID> 
       <CustomerCode>1112221</CustomerCode> 
       <FullUserName>MR DAVE GEORGE</FullUserName> 
       <StartDate>2010-01-01</StartDate> 
       <EndDate>2009-01-01</EndDate> 
      </Usage> 
      </soap:Body> 
     </soap:Envelope> 

</cfoutput> 
</cfsavecontent> 


<cfhttp 
url="http://portal/internet.asmx" 
method="post" 
result="httpResponse"> 

<cfhttpparam 
    type="header" 
    name="SOAPAction" 
    value="http://portal/internet.asmx/Usage" 
    /> 

<cfhttpparam 
    type="header" 
    name="accept-encoding" 
    value="no-compression" 
    /> 

<cfhttpparam 
    type="xml" 
    value="#trim(soapBody)#" 
    /> 

</cfhttp> 



<cfoutput> 
#httpResponse.fileContent# <!--- ouputs "connection failure" ---> 
    </cfoutput> 

非常感謝, 保羅

+2

嗨保羅,只想說:有什麼好尷尬的。我也用了12年的CF,很多我不知道,而且我每天都在學習很多東西。這是關於CFML的其中一件事情......你可以到現在爲止,而無需詢問,學習或排除故障,最終有時會在多年後結束! – 2010-12-09 00:21:08

+0

SOAP 1.2是一團糟,尤其是當CF僅支持1.1 AFAIK – Henry 2010-12-09 01:26:35

回答

0

要相信你的話,並承擔不能與CF做,因爲作爲@Henry指出它的SOAP 1.2。所以看起來像這需要直接使用Java,特別是帶有Java附件API(SAAJ)的Soap。這是在java包javax.xml.soap中,它不是標準Java發行版的一部分。取而代之的是Oracle的a separate download

Best end to end tutorial I could find關於建立與端點的連接,建立&發送請求以及接收和解析響應來自IBM的developerworks站點。預先警告說它涉及到了,並且這樣做需要在上述下載的ColdFusion安裝的類路徑中安裝幾個jar。

0

最簡單的方法是爲您的web服務create Java stubs然後創建一個java對象並在Coldfusion中調用java對象。

  1. 創建存根,JAR它們,把它們放在你的lib文件夾,然後重新啓動的ColdFusion
  2. 確保你可以看到jar文件在你的路徑(看看下面總結的CF管理員)。
  3. 這樣使用它:

    < cfobject名= 「MyObj中」 TYPE = 「Java」 的類= 「your.class.name」 行動= 「創造」 >
    <CFSCRIPT>
    ARGS = structNew ()
    myObj.webservicemethod(args);
    </CFSCRIPT >

相關問題