Coldfusion: cfinvoke timeout

Written on 19 March 2012, 03:57pm

Tagged with: , ,

Consider the following scenario: you make a cfinvoke to a remote web service, that takes a long time to execute. In the same, you want to be in control of your script, and present a timeout error message. The natural thing to do in this case is to use cfsetting requestTimeout.
Or, you can use the cfinvoke’s timeout attribute, as in the example below.

I created a ColdFusion component, to be used a web service: sleeping.cfc. This component has only one method – sleepit – that simulates a long process. In our case, it sleeps for 5 seconds.
The client – call_sleeping.cfm – is using the cfinvoke tag to call the sleepit() method, but it will only wait for 2 seconds (timeout=2). The error received after 2 seconds will be:

Could not perform web service invocation “sleepit”.

The code below.


<cfcomponent displayname="Sleeping beauty"  
	hint="Just sleeps for some seconds">
	<cffunction access="remote" 
    	<!---<cfset Sleep(5000)>--->
		<cfset thread = CreateObject("java", 
        <cfset thread.sleep(5000)>

        <cfreturn 1 />



	<cfinvoke webservice="url://sleeping.cfc?wsdl" method="sleepit" 
		returnvariable="result" refreshWSDL="yes" timeout="2" />
	<cfoutput>Success invoking method <strong>sleepit</strong></cfoutput>

    <cfdump var="#result#" label="Output" />

        <cfdump var="#cfcatch#" label="Error" />

Leave a response