Highlighted

cffunction return that is not a string

New Here ,
Nov 20, 2017

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

Views

621

Likes

Translate

Translate

Report

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

cffunction return that is not a string

New Here ,
Nov 20, 2017

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

Views

622

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 20, 2017 0
Engaged ,
Nov 21, 2017

Copy link to clipboard

Copied

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

-Nic

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 21, 2017 0
LEGEND ,
Nov 21, 2017

Copy link to clipboard

Copied

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

https://cfdocs.org/cffunction

HTH,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 21, 2017 0
Most Valuable Participant ,
Nov 22, 2017

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 22, 2017 0
Adobe Community Professional ,
Nov 22, 2017

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.

/Charlie (server troubleshooter, carehart.org)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 22, 2017 0
LEGEND ,
Nov 22, 2017

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,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 22, 2017 0