Journeyman CF
Exploring Amazon Web Services with ColdFusion MX
Amazon.com, the 'earth's biggest selection,' has exposed their entire catalog of products, product reviews and ratings, user-created book lists, and more via Web services. Whether you're new to Web services or not, and even if you don't care so much about accessing Amazon's data, it presents an interesting case study of doing Web services in CFMX. You might even be able to turn the opportunity into profit!
Reader Feedback : Page 1 of 1
#2 |
Charlie Arehart commented on the 11 Jul 2003
Mark, you're overreacting a bit, don't you think. Yes, the code does work. It just has the error you note when you pass it something it doesn't find. So the truth is it doesn't "always" work. I'm not meaning to split hairs. I had explained in the article that if some unexpected result came back (such as if there were no authors and you tried to loop over them), there could be an error just like you're seeing, and I spoke about using CFTRY to handle that. I'll grant that I hadn't tested what would happen if the entire search result came back empty. I'll make the same assertion I did in the article: slap a CFTRY around it. In this case, since the error arises on the CFINVOKE itself, put it in a CFTRY and CFCATCH any error. If it works when there is a result but not when there s not, this will suffice to prevent the error. If you want to go further and detect and handle different errors from the CFINVOKE (such as if the service is down, etc.), you can. I'll offer a simple example here but I'll leave expanding on it as an "exercise for the reader". I wasn't writing a production read example. Just meaning to give you enough to take the ball and run with it. Try this in place of the CFINVOKE: <cftry> <cfinvoke webservice= "[visit link]" method="keywordSearchRequest" returnvariable="aProductInfo"> <cfinvokeargument name="KeywordSearchRequest" value="#aKeywordRequest#"/> </cfinvoke> <cfcatch> <cfif cfcatch.message contains "Could not perform web service invocation"> No records found. <cfelse> Unexpected error in invocation of web service. </cfif> <cfabort> </cfcatch> </cftry> |
#1 |
Mark commented on the 11 Jul 2003
This code doesn't work! It's giving me a huge error message if Amazon doesn't have anything match the query results. Help! Mark |