I'm looking to create a web service that can be made available to anyone. I want to start by creating the component object, running an initialization method to set the user's unique keys, and then make a number of methods available that will use those keys for their operations.
so, the component code:
<cfcomponent output = "false">
<cfproperty name="AssociatesID" type="string">
<cfproperty name="DeveloperKey" type="string">
<!--- function to initialize the AssociateID of the component --->
<cffunction name="AmazonSearchInitiali
ze" access="remote" returntype="string" output="no">
<!--- Define the AssociatesID argument --->
<cfargument name="AssociatesID" type="string" required="yes">
<cfargument name="DeveloperKey" type="string" required="yes">
<!--- set the AssociatesID argument --->
<cfset this.AssociatesID = arguments.AssociatesID>
<cfset this.DeveloperKey = arguments.DeveloperKey>
<cfreturn>
</cffunction>
<!--- function to perform an Amazon.com keyword search --->
<cffunction name="AmazonKeywordSearch"
access="remote" returntype="string" output="no">
<cfargument name="mode" type="String" required="yes">
<cfargument name="display_page" type="String" required="no" default="1">
<cfargument name="search" type="String" required="yes">
<cfset var AmazonURL = "
http://xml.amazon.com/onca/xml3?t=webservices-20&dev-t=" & this.DeveloperKey & "&KeywordSearch=" & arguments.search & "&mode=" & arguments.mode & "&type=lite&page=" & arguments.display_page & "&f=xml">
<cfhttp url = "#AmazonURL#" method = "get" timeout="60">
<cfreturn cfhttp.fileContent>
</cffunction>
<!--- function to perform an Amazon.com ASIN search --->
<cffunction name="AmazonProductDetails
" access="remote" returntype="string" output="no">
<cfargument name="asin" type="String" required="yes">
<cfset var AmazonURL = "
http://xml.amazon.com/onca/xml3?t=webservices-20&dev-t=" & this.DeveloperKey & "&AsinSearch=" & arguments.asin & "&type=heavy&f=xml">
<cfhttp url = "#AmazonURL#" method = "get" timeout="60">
<cfreturn cfhttp.fileContent>
</cffunction>
</cfcomponent>
and the calling page:
<cfobject webservice="
http://www.joezizzo.com/cfc/whatever.cfc?wsdl" name="AmazonResourceFeed">
<cfinvoke webservice="#AmazonResourc
eFeed#" method="AmazonSearchInitia
lize" AssociatesID="#associates_
id#" DeveloperKey="#developer_k
ey#">
<cfinvoke webservice="#AmazonResourc
eFeed#" method="AmazonKeywordSearc
h" mode = "#url.mode#" display_page = "#url.page#" search = "#urlencodedformat(url.sea
rch)#" returnVariable="AmazonKeyw
ordSearchR
esults">
Now, it is my understanding that variables with THIS scope are available to all cfc methods, as well as the calling page, for the life of the object. This does not seem to be the case. I invoke AmazonSearchInitialize(), and then attempt to run AmazonKeywordSearch, and the THIS scope is not defined. I've also tried every other scope (including unnamed).
I could set these two init variables at the top of the component with hard coding, but that would defeat the purpose of making this remotely available to many users, wouldn't it?
I could also require every function call (such as AmazonKeywordSearch) to take developer and associate keys as arguments, but that is unnecessarily redundant.
Any ideas as to how a function can be run to set initializing variables that will persist for every method invocation?
Thanks