Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cffunction return that is not a string

New Here ,
Nov 20, 2017 Nov 20, 2017

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

997
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 21, 2017 Nov 21, 2017

Looks more or less like that code would work.  Can you post what the return structure looks like?

-Nic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 21, 2017 Nov 21, 2017

By default, CFFUNCTIONS return WDDX.  If you specifiy the attribute returnformat="plain", then you will get your string.

https://cfdocs.org/cffunction

HTH,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 22, 2017 Nov 22, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2017 Nov 22, 2017

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.


/Charlie (troubleshooter, carehart. org)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 22, 2017 Nov 22, 2017
LATEST

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,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources