Skip to main content
Participant
November 21, 2017
Pergunta

cffunction return that is not a string

  • November 21, 2017
  • 2 respostas
  • 1180 Visualizações

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

    Este tópico foi fechado para respostas.

    2 Respostas

    WolfShade
    Legend
    November 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,

    ^ _ ^

    Carl Von Stetten
    Legend
    November 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

    Charlie Arehart
    Community Expert
    Community Expert
    November 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)
    Inspiring
    November 21, 2017

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

    -Nic