Coldfusion RESTful webservice: object is not an instance of a class declaration

When I call the URL http://192.168.2.26:8080/rest/RestSample/season/1.json , I get the error message:

"Error", "ajp-bio-8012-exec-4", "03/01/13", "16:51:58", "RestSample", "the object is not an instance of the class declaration. Sequence of files included or processed : C: \ path_to \ api \ service.cfc '' "

This is the file /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> 

Edit # 1 : following this guide: http://www.anujgakhar.com/2012/02/20/using-rest-services-in-coldfusion-10/

Edit # 2 : my 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> 

I would also like to note that updating REST services in the ALWAYS administrator gives me the following message:

 Unable to refresh REST service. Application RestSample could not be initialized. Reason: The application does not contain any rest enabled CFCs. The application does not contain any rest enabled CFCs. 

However, I can delete them and add them via onRequestStart () without any problems.

Edit # 3

My current structure

/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()).concat("main\"), this.name); return true; } } </cfscript> 

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(); return userQry; } } </cfscript> 

I still get the following error:

 'object is not an instance of declaring class 
+4
source share
2 answers

I created the files under C:\ColdFusion10\cfusion\wwwroot (instead of the root of the IIS site) and was able to register the REST service through the admin console without any problems.

+1
source

Let's start a slightly simpler example and see if you can get into working condition. I have successfully configured a working REST service by following these steps:

Go to REST Services in your ColdFusion administrator and delete all existing REST registrations.

In the new directory of your web application root, create Application.cfc with the following contents (note that <cfscript> tags are not needed if you are on CF 9 or higher):

 component output="false" { this.name = "RestSample"; } 

In the same directory, create index.cfm with the following contents:

 <cfset restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()), "RestSample") /> Done. 

In the same directory, create service.cfc with the following contents:

 component restpath="season" rest="true" { remote struct function getSeasonsByUserId(numeric userid restargsource="Path") httpmethod="GET" restpath="{userid}" { return { 'hello': 'world' }; } } 

First go to index.cfm through your browser and make sure you see the text β€œFinish”.

Open the REST services in the ColdFusion administrator and make sure that you find that the REST service has been successfully registered.

Finally, go to the REST resource in your browser through / rest / RestSample / season / 123, and I hope you see a reliable "hello world".

Let me know if you still have problems and we will see what we can do.

+2
source

All Articles