Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Coldfusion webservices

    Hi,

    I am having trouble maintaing session information between webservice calls. I have two webserives running from a single file?
    First webservice creates a session setting few session variable.
    Second webservice (on the server side) uses the session variables(first set) to call other function?

    My application.cfm file
    Code:
    <CFAPPLICATION
    	NAME="Sha"
    	CLIENTMANAGEMENT="yes"
    	SESSIONMANAGEMENT="Yes"
    	SETCLIENTCOOKIES="yes"
    	SESSIONTIMEOUT="#createTimeSpan(0,1,0,0)#"
    	APPLICATIONTIMEOUT="#createTimeSpan(1,0,0,0)#"
    	clientStorage = "cookie">
    My file on the server:
    <cffunction name="setUpSession" access="remote" output="false" turntype="string" displayname="setUpWebUserSession">
    	<cfargument name="userName" required="true" default="">
    	<cfargument name="applicationToLogIn" required="true" default="">
    <cflock scope="session" throwontimeout="true" timeout="120" type="exclusive">
    <cfset session.WebUserUI = createObject("component", "org.atcc.webuser.client.presentation.WebUserUI")>
    <cfset session.WebUserUI.init()>
    	</cflock>
    <cfreturn true>
    </cffunction>
    <cffunction name="getProfileHTML" access="remote" displayname="getProfileHTML" output="false" returntype="string">
    	<cfset var profileHTML = "">
    	<cfsavecontent variable="profileHTML">
    	<cfoutput>#session.WebUserUI.getWebProfileHTML()#</cfoutput>
    	</cfsavecontent>
    	<cfreturn profileHTML>
    </cffunction>
    
    My Webservice invoation function:-
    
    <cfinvoke webservice="http://localhost:8080/CTiWebServicesAPI/ATCC/WebServicesAPI.cfc?wsdl"
    		method="setUpSession"
    		returnVariable="soo">
    	<cfinvokeargument name="userName" value="sha@gmail.com">
    	<cfinvokeargument name="applicationToLogIn" value="sha">
    </cfinvoke>
    <cfoutput> #soo# </cfoutput>
    <cfinvoke webservice="http://localhost:8080/CTiWebServicesAPI/console/library/BaseConsole.cfc?wsdl"
               method="getWebProfileHTML" 
    	returnvariable="profilehtml">
    		 <cfinvokeargument name="passedStruct" value="#passedStruct#"/>
    </cfinvoke>
    <cfoutput>#profilehtml#</cfoutput>
    
    O/p
    true
    Could not find session.WebUserUI or session.webUserUI not defined.

    Can anyone explain me why is the application not holding session variables between calls?
    What should I do?
    Please Help me?

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    NJ, USA
    Posts
    476
    Thanks
    2
    Thanked 70 Times in 69 Posts
    Well, first, are you actually in fact trying to create a web service with your CFC's? (As in, are other web servers going to access the components on your web server for information remotely, via web service?)

    If you are not using your CFC's for the web service purpose, and are just using them as local components (which it seems you are trying to do), then you do not want to be invoking methods in them via the "webservice" attribute of cfinvoke. This causes cfinvoke to create a separate http call to invoke methods in the CFC, rather than just invoking them directly on your server. You want to use the "component" attribute instead.

    If you are in fact making them actual web services for remote servers to access, then you cannot use session variables in the way you are using them. Check out this article, its all about programming web services. http://flex.sys-con.com/node/86108. Especially refer to section 2, "Session Management."

    As for your cfm file that is trying to invoke methods of those components, it is not creating your session because you are calling the cfc's via a "remote" call (by using the "webservice" attribute in cfinvoke), and the code in the cfc can't identify the client for who the session is supposed to be tied to when you call a cfc in that fashion. If you invoke these components through a local call, they will.

    Try this code instead, to call the methods of the components directly instead of remotely:
    Code:
    <cfinvoke
      component="CTiWebServicesAPI.ATCC.WebServicesAPI"
      method="setUpSession"
      returnVariable="soo">
           <cfinvokeargument name="userName" value="sha@gmail.com">
           <cfinvokeargument name="applicationToLogIn" value="sha">
    </cfinvoke>
    <cfoutput>#soo#</cfoutput>
    
    <cfinvoke 
      component="CTiWebServicesAPI.console.library.BaseConsole"
      method="getWebProfileHTML" 
      returnvariable="profilehtml">
           <cfinvokeargument name="passedStruct" value="#passedStruct#"/>
    </cfinvoke>
    <cfoutput>#profilehtml#</cfoutput>
    I don't know how your directory structure is set up, but the "CTiWebServicesAPI" folder would have to be a subdirectory of the web root. If it is not, then a mapping to it would have to be set up in the coldfusion administrator.

    Let me know if that helps, and if you're still having trouble, let me know if you are in fact trying to create web services, or just use coldfusion components.

    Also, check out the coldfusion reference's developer guide for help. http://livedocs.adobe.com/coldfusion/8/htmldocs/ Navigate to "ColdFusion Developers Guide" -> "Building and Using ColdFusion Components". The sections are relatively short, and provide a lot of the useful information for working with CFCs.

  • Users who have thanked Gjslick for this post:

    muddu_shafi (05-05-2009)

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I am trying to use CFC as webservice

    First of all, thanks for a detailed reply.

    Actually, I have created and posted CFC as a webservice using the access="remote" attribute in the <Cffunction>.
    Well, the webservice that I created internally calls other files with in the application which are deployed as an EAR file in the JBoss server.

    CTIWebservices, is my root directory and all other files reside inside them.So when I say org.atcc.erpproxy.****, it basicall is in this folder.
    Problem I am facing is maintaing state between calls as I have stated earlier.

    Can you throw some light on this matter?
    Thanks a lot..

  • #4
    Regular Coder
    Join Date
    Feb 2009
    Location
    NJ, USA
    Posts
    476
    Thanks
    2
    Thanked 70 Times in 69 Posts
    Ah, ok, then since you are actually trying to create a web service, you cannot maintain session variables between calls to the web service.

    The technical reason is because ColdFusion uses the client's CFID and CFTOKEN cookies to identify a user's session (and therefore, the user's session variables). These cookies are set on the client's web browser when they first access your site, and are subsequently sent with every new request from the client browser back to your site so that client can be identified between calls to pages. But, unlike regular calls to pages/CFCs from a client web browser, the CFID and CFTOKEN are not sent when you invoke a method in a webservice from ColdFusion. The http headers actually come back from the server to the calling cfinvoke line, asking for the "client" to set the CFID and CFTOKEN cookies, but this obviously doesn't happen as the "client" is not a web browser, it is your ColdFusion engine.

    That being said, you're going to have to find an alternative solution for creating this web service. I see that you want to instantiate a component into the session scope, but unfortunately that is not going to be an option. Again, read the section entitled "Session Management" in this article: http://flex.sys-con.com/node/86108. That will give you some ideas.

    I think your best bet is to follow what they did in that article, with using a database as storage for simulated sessions. You'll just have to re-instantiate that WebUserUI component in each method of the web service that uses it.

    Hope this points you in the right direction, but let me know if you have any other questions or are still having trouble.

    Greg


  •  

    Posting Permissions

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