Copy link to clipboard
Copied
I want to creat web serivice by cfc that return a string.
But the cfc return a struct.
How can I do ?
The client only accept return a string.
my web service code:
<cffunction name="wechar_tokenVerify" access="remote" returntype="string">
<cfreturn "132456">
</cffunction>
the client's http method is get
thanks
Copy link to clipboard
Copied
Looks more or less like that code would work. Can you post what the return structure looks like?
-Nic
Copy link to clipboard
Copied
By default, CFFUNCTIONS return WDDX. If you specifiy the attribute returnformat="plain", then you will get your string.
HTH,
^ _ ^
Copy link to clipboard
Copied
In addition to what @WolfShade said, you can also return as JSON or XML (depending on what the application consuming the web service needs).
-Carl
Copy link to clipboard
Copied
And just to round out the discussion, in case jyjun didn't catch it, the returnformat that Wolfshade offered is indeed distinct from (and can alter) the returntype attribute which you already have.
There's history behind all this, but the bottom line is that if you are calling a CFC and a remote method via http (not as a web service), then there are these differences in what's returned by default and how that returnformat overrides it.
In fact, you can also control what format you get back in the URL that you send to request such a remote method this way, by adding a &returnformat=plain, for instance (not string, as I first wrote by mistake here).
That ability to override the format via the URL is not covered in the cfdocs page that was offered, since that's based on the CFML Reference, which only discusses the cffunction tag itself. But it is discussed in the CF Developers Guide section on the topic, and also in a blog post from Ray Camden back 10 years ago when all this was initially bubbling to the surface, if you want to better appreciate how it all came about.
Copy link to clipboard
Copied
I hate to add yet another possibility to this (for the OP's sake), but you could also (during development) CFDUMP the returned result if it is WDDX or JSON and program the callback to 'sniff out' the desired string from the wrapped return result by using REreplaceNoCase() and backreferences (or JavaScript replace()) to remove the wrapper. But that would probably be more complex than the OP desires.
Just a thot.
V/r,
^ _ ^