Important *Gotcha* for web service and application.cfc users

I recently learned about a neat feature of Coldspring that allows me to create remote proxy's of beans. I went through the doc and set everything up per examples, and my remote proxy's were generated, woohoo! So, I setup my function to return a proper value and I bind a cfgrid to the remote object. I invoke it, and get:

CFGRID: The response is empty

Weird.. so I try to call the CFC directly in the url, and I get a completely blank page. Fast forward about 2 hours of digging through CF and IIS logs trying to figure out why no error is being throw and no output is being displayed, then I find a web post about using cfc's and the onRequest function. For some reason, if you have anything in your onRequest, your call to the remote cfc will fail and give you an illuminating blank response! Here is what I placed in my onRequestStart function to fix it up, and now remoting and web service requests are working perfectly ;)

 

<cffunction name="onRequestStart" returnType="boolean" output="false">
      <cfargument name="thePage" type="string" required="true">   
      
      <!---// Necessary code to determine if a cfc is being requested and
            remove the onRequest function from this currently running process,
            otherwise a blank page gets returned and no error thrown //--->
      <cfif listLast(arguments.thePage, '.') eq 'cfc' OR isSOAPRequest()>
         <cfset StructDelete( THIS, "OnRequest" ) />
      </cfif>
   <cfreturn true>
  </cffunction>

 

Digg StumbleUpon Facebook Technorati Fav newsvine reddit FARK Google Bookmarks
  1. justin

    #1 by justin - March 6, 2008 at 10:19 AM

    I remember when application.cfc first came out and we were all learning about it. This was always mentioned, although it was always with respect to flash remoting. It was a big deal, but not many people were doing flash remoting, and it sounded really confusing. I've never used onRequest because I've always been afraid of what I might break!
  2. John Fitzgerald

    #2 by John Fitzgerald - October 27, 2008 at 11:49 PM

    Thank you! You saved me a lot (more) time digging.

Comments are closed.