2009-10-21 61 views
1

我正在使用提供基本CRUD功能的web服务。 Retrieve很容易处理,但我在使用Create时遇到了问题(我还没有搞清楚Update或Delete函数)。ColdFusion,WSDL和扩展的复杂类

update函数只有一个参数。这是WSDL中的一个zObject。但是,这是一个通过我实际需要传递的通用对象。例如,如果我想创建一个帐户,我传递一个扩展zObject定义的Account对象。

我不能为我的生活找出如何让CF让我做到这一点。

回答

3

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

我真的很感激这个建议。在这个问题和其他问题之间,整合在我尝试完成之前就被取消了,所以我不会将其标记为正确的(因为我不能确认),但我会给它一个赞成票。 – 2009-10-30 14:34:51

1

我使用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();

+0

这很好。我曾试图用生成的.class文件使用JavaLoader,并且有奇怪的ClassLoader问题。从webservice对象获取classLoader是一种天才。 – 2012-07-02 08:36:36