我正在使用提供基本CRUD功能的web服務。 Retrieve很容易處理,但我在使用Create時遇到了問題(我還沒有搞清楚Update或Delete函數)。ColdFusion,WSDL和擴展的複雜類
update函數只有一個參數。這是WSDL中的一個zObject。但是,這是一個通過我實際需要傳遞的通用對象。例如,如果我想創建一個帳戶,我傳遞一個擴展zObject定義的Account對象。
我不能爲我的生活找出如何讓CF讓我做到這一點。
我正在使用提供基本CRUD功能的web服務。 Retrieve很容易處理,但我在使用Create時遇到了問題(我還沒有搞清楚Update或Delete函數)。ColdFusion,WSDL和擴展的複雜類
update函數只有一個參數。這是WSDL中的一個zObject。但是,這是一個通過我實際需要傳遞的通用對象。例如,如果我想創建一個帳戶,我傳遞一個擴展zObject定義的Account對象。
我不能爲我的生活找出如何讓CF讓我做到這一點。
ColdFusion爲其Web服務功能實現了Apache Axis引擎。 不幸的是,CF並沒有充分利用SOAP對象模型,並允許CF開發人員「構建」一個服務(或其子類)的不同對象。
謝天謝地,我們可以做些什麼。當您第一次訪問WSDL時,Axis會生成一組存根對象。這些是常規的java類,其中包含對象的基本屬性的 獲取器和設置器。我們需要使用這些 存根來構建我們的對象。
然而,爲了使用這些存根,我們需要將它們添加到ColdFusion 類路徑:
Step 1) Access the WSDL in any way with coldfusion.
Step 2) Look in the CF app directory for the stubs. They are in a "subs"
directory, organized by WSDL.like:
c:\ColdFusion8\stubs\WS\WS-21028249\com\foo\bar\
Step 3) Copy everything from "com" on down into a new directory that exists in
the CF class path. or we can make one like:
c:\ColdFusion8\MyStubs\com\foo\bar\
Step 4) If you created a new directory add it to the class path.
A, open CF administrator
B. click on Server settings >> Java and JVM
C. add the path to "ColdFusion Class Path". and click submit
D. Restart CF services.
Step 5) Use them like any other java object with <CFObject /> or CreateObject()
MyObj = CreateObject("java","com.foo.bar.MyObject");
Remember that you can CFDump the object to see the available methods.
<cfdump var="#MyObj#" />
您的帳戶對象應在存根。如果由於某種原因需要創建它,則需要在新的Java類文件中執行該操作。
通常,在使用這麼多的Java時,cfscript是一種可行的方式。
最後,代碼是這樣的:
<cfscript>
// create the web service
ArgStruct = StructNew();
ArgStruct.refreshWSDL = True;
ArgStruct.username = 'TestUserAccount';
ArgStruct.password = '[email protected]';
ws = createObject("webservice", "http://localhost/services.asmx?WSDL",ArgStruct);
account = CreateObject("java","com.foo.bar.Account");
account.SetBaz("hello world");
ws.Update(account);
</cfscript>
我使用ColdFusion的批判同意,但是,公佈解決方案還不能很好地WSDL的變化做出反應。
謝天謝地,CF可以訪問對象上的所有底層Java方法。這包括'反思'。雖然CreateObject不知道存根對象,但創建webservice的類加載器卻行。
ws = createObject("webservice", "http://localhost/services.asmx?WSDL",ArgStruct); account = ws.getClass().getClassLoader().loadClass('com.foo.bar.Account').newInstance();
這很好。我曾試圖用生成的.class文件使用JavaLoader,並且有奇怪的ClassLoader問題。從webservice對象獲取classLoader是一種天才。 – 2012-07-02 08:36:36
我真的很感激這個建議。在這個問題和其他問題之間,整合在我嘗試完成之前就被取消了,所以我不會將其標記爲正確的(因爲我不能確認),但我會給它一個贊成票。 – 2009-10-30 14:34:51