Web Service Help

This is a discussion on Web Service Help within the Cold Fusion forums in Application Servers & Tools category; I am setting up a web service for my first time. I have two "clients" that would like to access this web service but they would like to pass data to me differently. One would like to pass it as an array and the other would like to pass it as individual strings. How would I write the conditional statement in the CFC? CF doesn't seem to like the following... <cfif cgi.remote_host EQ "##.##.##.##"> assign argument vars to values passed as array <cfelseif cgi.remote_host EQ "XX.XX.XX.XX"> assign argument vars to values passed as strings </cfif>...

Go Back   Application Development Forum > Application Servers & Tools > Cold Fusion

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-05-2008, 06:24 PM
jbreslow
Guest
 
Default Web Service Help

I am setting up a web service for my first time. I have two "clients" that
would like to access this web service but they would like to pass data to me
differently. One would like to pass it as an array and the other would like to
pass it as individual strings. How would I write the conditional statement in
the CFC? CF doesn't seem to like the following...

<cfif cgi.remote_host EQ "##.##.##.##">
assign argument vars to values passed as array
<cfelseif cgi.remote_host EQ "XX.XX.XX.XX">
assign argument vars to values passed as strings
</cfif>

Reply With Quote
  #2  
Old 09-05-2008, 07:03 PM
Dan Bracuk
Guest
 
Default Re: Web Service Help

You write two functions. Each accepts the data as sent and converts it to something you want. Then you send this data to a third function that processes it.
Reply With Quote
  #3  
Old 09-06-2008, 03:36 AM
BKBK
Guest
 
Default Re: Web Service Help

I wouldn't bother about IPs. In fact, I wouldn't differentiate between clients
as you've done. I would keep it general, using the 'any' type. Something along
the following lines:





<!--- === webServicetest.cfm === --->
<!--- array --->
<cfset arr = arrayNew(1)>
<cfset arr[1]='John'>
<cfset arr[2]='Smith'>

<!--- string --->
<cfsavecontent variable="str">
<name>
<first>John</first>
<last>Smith</last>
</name>
</cfsavecontent>

<!--- web service object --->
<cfset ws_obj = CreateObject("webservice",
"http://127.0.0.1:8500/website/wsTest.cfc?wsdl")>

<!--- First, call web service with arr, then with str --->
<cfset ws_return = ws_obj.arrayOrString(arr)>
<cfdump var="#ws_return#">


<!--- === wsTest.cfc === --->
<cfcomponent>
<cffunction name="arrayOrString" access="remote" returntype="string">
<cfargument type="any" name="arg" >

<cfset returnString = "Neither array nor string">

<cfif isArray(arguments.arg)>
<!--- code for array arg --->
<cfset returnString = "Argument was an array">
<cfelseif isSimplevalue(arguments.arg)>
<!--- code for string arg --->
<cfset returnString = "Argument was a string or could be converted to string">
<cfelse>
<!--- Reject arg, perhaps? --->
</cfif>

<cfreturn returnString>

</cffunction>
</cfcomponent>

Reply With Quote
  #4  
Old 09-09-2008, 11:01 AM
germ
Guest
 
Default Re: Web Service Help

BKBK is right, don't do checkups for IPs in your CFCs because by doing so, you
prevent your code from beeing usefull at another time, for another project and
another client. Both ideas that Dan and BKBK gave you seem good. I for one
would probably opt for BKBK's solution (checking if the argument is an array or
not and processing the data accordingly).

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 06:53 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.