Professional Web Applications Themes

Web Service problems - Coldfusion - Advanced Techniques

I've been at this for about 19 hours now... I'm on CFMX6.1 running under JRun4 (latest update applied) I'm trying to create a CFC on our site that encapsulates functions to do with the currently logged in User. I've created the CFC and, called using createObject("component"), it all works great. However, I'm also trying to set it up as a webservice. This seems very simple, however, I am getting errors like 'method not found' when I know the method is definitely there and set up as access="remote". The central problem appears to be that the init() method (which takes a ...

  1. #1

    Default Web Service problems

    I've been at this for about 19 hours now...
    I'm on CFMX6.1 running under JRun4 (latest update applied)

    I'm trying to create a CFC on our site that encapsulates functions to do with
    the currently logged in User.
    I've created the CFC and, called using createObject("component"), it all works
    great.
    However, I'm also trying to set it up as a webservice. This seems very simple,
    however, I am getting errors like 'method not found' when I know the method is
    definitely there and set up as access="remote".

    The central problem appears to be that the init() method (which takes a
    parameter) doesn't return the object properly.

    I'll post the code here in the hope that someone can tell me what's wrong.
    Stupidly simple, I know...

    Getting the WSDL, by the way, succeeds in getting something meaningful and
    correct back.

    Hope someone can help!

    --
    Mike Horne

    This is the CFC:

    <cfcomponent displayname="usermdh" hint="User functions" output="no">
    <cffunction name="init" displayname="Initialise" hint="Inits the user object"
    output="true" returntype="ws.Private.usermdh" access="remote">
    <cfargument name="personID" required="yes" type="numeric" hint="Foreign key
    to person table member_no">
    <cfset variables.personID = arguments.personID>
    <cfquery datasource="#request.datasources.main#" name="variables.qUser">
    select rTrim(username) as username,
    rTrim(password) as password,
    rTrim(personID) as personID
    from users
    where personID=<cfqueryparam cfsqltype="cf_sql_integer"
    value="#variables.personID#">
    </cfquery>
    <cfreturn this/>
    </cffunction>

    <cffunction name="getpersonid" displayname="getpersonid" hint="Gets personID"
    output="false" returntype="numeric" access="remote">
    <cfreturn variables.personID/>
    </cffunction>
    </cfcomponent>


    And this is what I'm doing to call the webservice:
    <cfset oUser = CreateObject("webservice",
    "#server#/ws/private/usermdh.cfc?wsdl").init("#client.memberno#")>
    <cfoutput>#oUser.getpersonid()#</cfoutput>

    recantha Guest

  2. #2

    Default Re: Web Service problems

    I am not sure that the variables.personid created in your init function is
    available to your getpersonid function. Try making it a property of your
    component. That's the approach that I take, and it works with my cfc's.

    Originally posted by: recantha
    I've been at this for about 19 hours now...
    I'm on CFMX6.1 running under JRun4 (latest update applied)

    I'm trying to create a CFC on our site that encapsulates functions to do with
    the currently logged in User.
    I've created the CFC and, called using createObject("component"), it all works
    great.
    However, I'm also trying to set it up as a webservice. This seems very simple,
    however, I am getting errors like 'method not found' when I know the method is
    definitely there and set up as access="remote".

    The central problem appears to be that the init() method (which takes a
    parameter) doesn't return the object properly.

    I'll post the code here in the hope that someone can tell me what's wrong.
    Stupidly simple, I know...

    Getting the WSDL, by the way, succeeds in getting something meaningful and
    correct back.

    Hope someone can help!

    --
    Mike Horne



    Dan Guest

  3. #3

    Default Re: Web Service problems

    I thought that was the point of of the variables scope? According to o'Reilly
    DevCentre 'Variables in the variables scope are available anywhere in the CFC,
    meaning any method in the CFC can use the variable.
    I can see the point of cfproperty, to expose the 'this' scope to
    webservices... But we're talking a very simple thing here...

    I've attached another bit of code... see what you make of this... another
    cffunction returning JUST the number 1...
    I get no output!



    Same component...
    <cffunction name="getdemo" displayname="getdemo" output="false"
    returntype="numeric" access="remote">
    <cfreturn 1/>
    </cffunction>


    <cfset oUser = CreateObject("webservice",
    "#request.InternalWebServices.Server#/ws/private/usermdh.cfc?wsdl").init("#clien
    t.memberno#")>
    <cfoutput>#oUser.getdemo()#</cfoutput>


    NO output from above...

    recantha Guest

  4. #4

    Default Re: Web Service problems

    What happens if you do this?
    <cfobject component="usermdh" name="oUser">
    <cfset x=oUser.getdemo()>
    <cfdump var="#x#">


    Originally posted by: recantha
    I thought that was the point of of the variables scope? According to o'Reilly
    DevCentre 'Variables in the variables scope are available anywhere in the CFC,
    meaning any method in the CFC can use the variable.
    I can see the point of cfproperty, to expose the 'this' scope to
    webservices... But we're talking a very simple thing here...

    I've attached another bit of code... see what you make of this... another
    cffunction returning JUST the number 1...
    I get no output!





    Dan Guest

  5. #5

    Default Re: Web Service problems

    That works... I'm not having trouble with the CFC except when I try to use it
    as a web service.
    For instance, I'm using createObject("webservice..."), dumping the object (and
    I can see the methods) but then just doing object.method() doesn't work.
    Also, as suggested below, when I do object.init(personID) (which returns
    'this' of type usermdh), I don't get the object back.
    So, I would expect:
    <cfset oObj = createobject("webservice", "url")>
    to return the object,
    but I would also expect
    <cfset oObj2 = oObj.init(12345)> to return the object as well...

    Or am I just expecting too much from it?

    recantha Guest

  6. #6

    Default Re: Web Service problems

    That's beyond my level of expertise, but, let's get back to the variables scope
    you are using. I'm not sure, but, I think that by using it, not only will the
    variable be available to entire cfc, which is good, it will also become
    available to the template calling the function, which might not be so good.

    Originally posted by: recantha
    That works... I'm not having trouble with the CFC except when I try to use it
    as a web service.
    For instance, I'm using createObject("webservice..."), dumping the object (and
    I can see the methods) but then just doing object.method() doesn't work.
    Also, as suggested below, when I do object.init(personID) (which returns
    'this' of type usermdh), I don't get the object back.
    So, I would expect:
    <cfset oObj = createobject("webservice", "url")>
    to return the object,
    but I would also expect
    <cfset oObj2 = oObj.init(12345)> to return the object as well...

    Or am I just expecting too much from it?



    Dan Guest

  7. #7

    Default Re: Web Service problems

    Again, according to something I've read... variables are internal to the CFC,
    the scope that exposes things to the outside world is the 'this' scope... which
    is what I think <cfproperty> refers to...

    It's really very frustrating, this...

    recantha Guest

  8. #8

    Default Re: Web Service problems

    How about creating an instance of ws.Private.usermdh using cfObject or
    createObject and returning that instead of just this which would seem to be an
    empty object. If there needs to be persistance then create some variables
    between the cfcomponent and the first cffunction and use accessors to get at it
    (like getpersonid). I don't see from your initial code how you tie anything
    together or store anything like personId; you don't seem to make assignments to
    anything.

    mrampson Guest

  9. #9

    Default Re: Web Service problems

    My understanding is that a webservice is stateless. That means the variables
    and this scope are no good. Any caching of data would have to be done in a
    persistent scope like application.

    I don't think returning this from your init() method is doing what you think
    it is either. when you set your variable to createobject("webservice","...")
    you get a "webservice" object, but if you tag init() onto that you don't get a
    webservice object. in other words createObject() is doing something for you
    that init doesn't know how to do.

    This link has an example of outputting the results of a
    webService:http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/webser17.htm

    Hope that helps.

    leeHow Guest

Similar Threads

  1. Web Service problems
    By sdmah in forum Macromedia Flash Data Integration
    Replies: 2
    Last Post: March 10th, 02:42 PM
  2. Problems with printing from web service
    By Baczek in forum ASP.NET Web Services
    Replies: 2
    Last Post: November 19th, 10:59 PM
  3. Service Pack 2 Problems
    By Shirley in forum Web Design
    Replies: 2
    Last Post: September 14th, 05:04 PM
  4. Problems with web service access
    By Sky Fly in forum ASP.NET Web Services
    Replies: 3
    Last Post: November 29th, 11:29 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139