After a bit of reflection, I'm taking both suggestions.  Per Rick's suggestion, 
I'm creating a wrapper function that just calls the "real" function.  The 
wrapper is the webservice version of the function, and takes all the "real" 
function arguments, and an additional "returnformat" argument.  This argument 
can be, for now, "querystring","xml", or "struct".  

If the caller chooses querystring, then I return a URL encoded querystring for 
the results (replacing the ampersand with pipes as the outer delimiters).  If 
the caller chooses xml, then I return xml as a string that the caller can then 
re-serialize into an XML document.  If we have any partners that use CF, then 
they can get a struct back.

Thanks to all for the advice.

For anybody who's interested, here's my "formatreturn" code, plus one 
supporting function (note: this code only works on structures that have simple 
values--if the structure values are arrays, queries, etc, then this code bombs):

<cffunction name="formatreturn" access="package" returntype="any" 
output="false">
 <cfargument name="struct" type="struct" required="true">
 <cfargument name="conversion" type="string" required="false" 
default="querystring">
        
 <cfset var res = "">
 <cfset var value = "">
        
 <cfswitch expression=#arguments.conversion#>
   <cfcase value="querystring">
        <cfloop collection=#arguments.struct# item="key">
          <cfset value = structfind(arguments.struct,key)>
           <cfif NOT len(value)><cfset value="[empty string]"></cfif>
           <cfset res = listappend(res,"#key#=#value#","|")>
        </cfloop>
        <cfset res = urlencodedformat(res)>
    </cfcase>

    <cfcase value="xml">
     <cfset res = this.structToXml(arguments.struct,"results")>
    </cfcase>

    <cfcase value="struct">
     <cfreturn arguments.struct>
    </cfcase>

    <cfdefaultcase>
     <cfreturn "">
    </cfdefaultcase>
   </cfswitch>
        
   <cfreturn res>

</cffunction>


<cffunction name="structToXML" returnType="string" access="package" 
output="false">
        <!--- Apparently, using the underlying Java code is far faster than CF 
stuff --->
        <cfargument name="struct" type="struct" required="true">
        <cfargument name="rootelement" type="string" required="true">
        <cfset var s = 
createObject('java','java.lang.StringBuffer').init('<?xml version="1.0" 
encoding="UTF-8"?>')>
        <cfset var key = "">

        <cfset s.append("<#arguments.rootelement#>")>   
        <cfloop collection=#arguments.struct# item="key">
                <cfset key = lcase(key)>
                <cfset 
s.append("<#key#>#xmlformat(structfind(arguments.struct,key))#</#key#>")>
        </cfloop>

        <cfset s.append("</#arguments.rootelement#>")>
        
        <cfreturn s.toString()>         
</cffunction>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7
The most significant release in over 10 years. Upgrade & see new features.
http://www.adobe.com/products/coldfusion

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:271375
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to