| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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> |
|
#2
| |||
| |||
| 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. |
|
#3
| |||
| |||
| 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> |
|
#4
| |||
| |||
| 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). |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.