Web services Coldfusion RESTful webservice:对象不是声明类的实例

Web services Coldfusion RESTful webservice:对象不是声明类的实例,web-services,rest,coldfusion,cfml,Web Services,Rest,Coldfusion,Cfml,当我调用URLhttp://192.168.2.26:8080/rest/RestSample/season/1.json我得到了错误信息: “Error”、“ajp-bio-8012-exec-4”、“03/01/13”、“16:51:58”、“RestSample”、“对象不是声明类的实例。包含或处理的特定文件序列为:C:\path\u to\api\service.cfc”“。” 这是/api/service.cfc文件: <cfscript> component restpa

当我调用URL
http://192.168.2.26:8080/rest/RestSample/season/1.json
我得到了错误信息:

“Error”、“ajp-bio-8012-exec-4”、“03/01/13”、“16:51:58”、“RestSample”、“对象不是声明类的实例。包含或处理的特定文件序列为:C:\path\u to\api\service.cfc”“。”

这是
/api/service.cfc
文件:

<cfscript>
component restpath="season" rest="true"
{

    remote query function getSeasonsByUserId(numeric userid restargsource="Path") httpmethod="GET" restpath="{userid}"
    {
        var response = "";
        var qry = new Query();
        var userQry = "";

        qry.setSQl("select * from mytable where userID = :userid");
        qry.addParam(name="userid", value="#arguments.userid#", cfsqltype="cf_sql_numeric");
        userQry = qry.execute().getResult();

        if(userQry.recordcount == 0)
        {
            response = userQry;
        } else {
            throw(type="Restsample.SeasonsNotFoundError", errorCode='404', detail='Seasons not found');
        }

        return response;
    }    
}   
</cfscript>
但是,我可以删除它们并通过onRequestStart()添加它们,而不会出现任何问题

编辑#3

我目前的结构

/api/main/service.cfc /api/application.cfc /api/index.cfm

application.cfc

<cfscript>
component output="false"
{
    this.name = "RestSample";
    this.applicationTimeout = createTimespan(0,0,0,0);
    this.datasource = "mydsn";
    this.username = "";
    this.password = "";

    //this.restsettings.skipCFCWithError = true;

    public boolean function onRequestStart()
    {
        restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()), this.name);

        return true;
    }
}
</cfscript>
<cfscript>
component output="false"
{
    this.name = "RestSample";
    this.applicationTimeout = createTimespan(0,0,0,0);
    this.datasource = "mydsn";
    this.username = "";
    this.password = "";

    this.restsettings.skipCFCWithError = true;

    public boolean function onRequestStart()
    {
        restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()).concat("main\"), this.name);

        return true;
    }
}
</cfscript>

让我们开始一个简单一点的例子,看看是否可以进入工作状态。我已通过以下步骤成功设置了working REST服务:

转到ColdFusion管理员中的REST服务并删除任何现有的REST注册

在web根目录的新目录中,使用以下内容创建Application.cfc(请注意,如果您使用的是CF 9或更高版本,则不需要使用
标记):

在同一目录中,使用以下内容创建index.cfm:

<cfset restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()), "RestSample") />
Done.
component restpath="season" rest="true"
{
    remote struct function getSeasonsByUserId(numeric userid restargsource="Path") httpmethod="GET" restpath="{userid}"
    {
        return {
            'hello': 'world'    
        };
    } 
}
首先,通过浏览器浏览到index.cfm,并验证是否看到文本“完成”

在ColdFusion Administrator中打开REST服务,并验证您是否看到REST服务已成功注册

最后,通过/REST/RestSample/seasure/123在浏览器中浏览REST资源,希望您能看到可靠的“hello world”


如果您仍然有问题,请告诉我,我们将看看我们能做些什么。

我在
C:\ColdFusion10\cfusion\wwwroot
(而不是站点的IIS根目录)下创建了文件,并且能够通过管理控制台注册REST服务,没有任何问题。

我没有使用CF的REST实现,但那应该是一次投掷吗?@PeterBoughton我不这么认为。。。我的映射是RestSample,因此它也应该是RestSample?老实说,我是按照这方面的教程进行的。诊断问题的第一步是确定错误的来源。删除(或注释掉)if并将return更改为
returnuserqry
以查看是否存在错误。(注意,
==0
是背对背的,无论如何都是不必要的。)在问题中包含指向教程的链接-这样,如果您误解了说明或教程是错误的,可以检查它。@PeterBoughton我去掉了if语句,并返回了查询(从管理控制台中删除rest服务并重新添加后)…相同的错误。另请注意(如下面教程的注释所述),您必须创建一个index.cfm以刷新REST服务。我有index.cfm并应用了您的修复程序。我仍然遇到相同的问题。我复制了您的文件,下面是我得到的:“错误”,“ajp-bio-8012-exec-10”,“03/06/13”,“13:01:51”,“包含或处理的文件的具体顺序是:“””哇。我对你的决心印象深刻。如果我是你的话,我现在应该已经拿起了太妃糖。我不知道你的错误是什么意思。你什么时候收到的错误以及它是如何表现出来的?你有没有查看你的错误日志,看看你是否能找到更多细节?自从你开始havi以来,你是否重新启动了CFng麻烦?我在Win7 Pro上尝试了这个设置,CF10本身就可以了。我想知道为什么它在我的VM上不起作用。与此同时,我只是创建了一个输出JSON的页面,我有一个需要它的进程。我没有重新启动,我今天晚些时候会尝试。日志显示了我所做的,没有其他内容。
'object is not an instance of declaring class
component output="false"
{
    this.name = "RestSample";
}
<cfset restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()), "RestSample") />
Done.
component restpath="season" rest="true"
{
    remote struct function getSeasonsByUserId(numeric userid restargsource="Path") httpmethod="GET" restpath="{userid}"
    {
        return {
            'hello': 'world'    
        };
    } 
}