我有一个 CFC,我将使用 ?wsdl 作为 SOAP Web 服务来访问它。
如果我直接在浏览器中调用 CFC,我的结果会很好:
http://server/webservice/calc.cfc?method=doStuff&foo=bar
如果我尝试将其作为 Web 服务访问:
ws = CreateObject("webservice", 'http://server/webservice/calc.cfc?wsdl');
result = ws.doStuff('bar');
我收到一个错误:
Cannot perform web service invocation doStuff.
The fault returned when invoking the web service operation is:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: coldfusion.xml.rpc.CFCInvocationException:
[coldfusion.xml.rpc.CFCInvocationException : [java.lang.ClassNotFoundException :
com.calculations.calc][java.lang.NullPointerException : null]]
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:coldfusion.xml.rpc.CFCInvocationException: [coldfusion.xml.rpc.CFCInvocationException : [java.lang.ClassNotFoundException :
com.calculations.calc][java.lang.NullPointerException : null]]
at coldfusion.xml.rpc.CFComponentSkeleton.__createCFCInvocationException(CFComponentSkeleton.java:733)
at coldfusion.xml.rpc.CFComponentSkeleton.__convertOut(CFComponentSkeleton.java:359)
at webservice.calc.doStuff(/var/www/vhosts/server/httpdocs/webservice/calc.cfc)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.r... ''
问题是因为 doStuff 函数在其中声明了一个 CFC 的实例:
remote struct function doStuff(foo) {
var objReturn = {};
objReturn.msg = 'A message';
// do a calculation
var objCalc = new com.calculations.calc(foo);
objReturn.calc = objCalc;
return objReturn;
}
因此,我用作 Web 服务的 CFC 在函数中声明了另一个 CFC。直接浏览到我的 web 服务 CFC 工作正常,但尝试使用 CreateObject/webservice 路由调用它失败,因为它无法创建com.calculations.calc组件的实例。
更新:
如果我刷新页面几次,有时错误会变为:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: coldfusion.xml.rpc.CFCInvocationException:
[coldfusion.xml.rpc.CFCInvocationException : [java.lang.ClassNotFoundException :
com.calculations.calc][coldfusion.xml.rpc.CFCInvocationException :
returnType must be defined for remote CFC functions.]]
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:coldfusion.xml.rpc.CFCInvocationException:
[coldfusion.xml.rpc.CFCInvocationException : [java.lang.ClassNotFoundException :
com.calculations.calc][coldfusion.xml.rpc.CFCInvocationException :
returnType must be defined for remote CFC functions.]]
at coldfusion.xml.rpc.CFComponentSkeleton.__createCFCInvocationException(CFComponentSkeleton.java:733)
at coldfusion.xml.rpc.CFComponentSkeleton.__convertOut(CFComponentSkeleton.java:359)
at webservices.TaxCalc.feed.getTaxCalc(/var/www/vhosts/server/httpdocs/webservice/calc.cfc)
at sun.reflect.Nat... ''
这是要求返回类型,但 com.calculations.calc 的 init 函数已返回 this;