Sep
09

Consuming a Web Service through Flash Remoting and CFForm

19 comments Posted by: Laura Arguello

One of the lesser-known features of the Flash Remoting gateway is to act as a proxy to a web service. Using this proxy, you can effectively circumvent the cross-domain restrictions in the flash player, as all calls are local to the flash movie.

It turns out to be very easy to make the call. It is almost exactly the same as calling a local CFC

What changes is that instead of setting our service to "myPath.to.cfc", we set it to the actual web service address:

myService = connection.getService(
"http://weblogs.macromedia.com/mxna/webservices/mxna2.cfc?wsdl", responseHandler );

and then call the desired function:

myService.getMostRecentPosts(50,0,1);

I am using the MXNA Web Service (http://weblogs.macromedia.com/mxna/webservices/mxna2.cfc?wsdl) as an example.

The tricky part is that the Web Service Proxy is not enabled by default in ColdFusion’s Remoting gateway. To enable it, open the gateway-config.xml file in C:\CFusionMX7\wwwroot\WEB-INF (or similar path) and uncomment

<adapter>coldfusion.flash.adapter.CFWSAdapter</adapter>

inside the node near the top. Then restart ColdFusion.

View live example
Download the source

Category: CFForm | ColdFusion | Flash Remoting |

19 Comments so far

Write yours
Asher Gilbert
Recently, ASFusion has posted some excellent articles on the use of the Flex components on CF MX.
I've just finished building this photo album application using the remoting features and upload features recently explained on this blog. Thanks alot guys. Top Draw!
&lt;br&gt;
&lt;a href=&quot;http://varian.zealio.com/screenshots/photoAlbum.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://varian.zealio.com/screenshots/photoAlbum-thumb.jpg&quot; width=&quot;210&quot; height=&quot;166&quot; border=&quot;0&quot;&gt;&lt;/a&gt;
Michael
2. Michael wrote on September 27, 2005 at 9:27 PM
Just wanted to say YOU PEOPLE ROCK! Flash forms were useless before you, now they are important tools. Now, for my question. With the new enhancements to CF forms in 7.01, what would be a good reference book to pick up to help me with flash forms and actionscript.

I have used most of the examples on the site to create rich interactive forms, but want to move furthur and hoped you could push me in the right direction.

Thanks in advance
Nahuel
Hi Michel
We have a small list with some great books.
http://www.asfusion.com/bookmarks/category/flash-books
Michael
Thanks for the help!
veejay
5. veejay wrote on October 25, 2005 at 12:55 PM
Is there any way of consuming WebServices without remoting?? I need it thru ActionScript. Any code will help.

Laura
veejay,
Do you want to do that in a cfform? If so, no, it is not possible.
If you want to do it in Flash (not cfform) check the Flash documentation for the Web Service component.
Douglas Knudsen
7. Douglas Knudsen wrote on February 08, 2006 at 1:46 PM
I'm really late to this whole conversation, but has anyone got this working on a HostMySite account? I got them to setup the flash remoting gateway thingy, but I keep getting a HTTP BASIC AUTH security popup wanting a user name and password. ????
Douglas Knudsen
8. Douglas Knudsen wrote on February 08, 2006 at 8:55 PM
ok...got it working. The fine folks at HostMySite hooked it up!
John Barrett
Thanks you so much`-`!
Laura, thanks so much for this, I am reading this, and I got it to work on my Mac, and I am actully starting to understand`-`

I am so stoked a local way of checking the lastest blogs, and with flash forms WOW!! It is a beautiful application`-`

One question?
What happen to the link to buy you something? Am I blind, or did you take the amazon wish list off??

Thanks again!`-`
John
Lesley
10. Lesley wrote on July 25, 2006 at 10:30 AM
I am trying to understand flash remoting, but I can't seem to get it to work.

I am getting the error Element COMPONENTPATH is undefined in REQUEST.

Here is the code that is in question:
Public function setUpRemoting(): Void{
      <cfoutput>
      var connection:mx.remoting.Connection = mx.remoting.NetServices.createGatewayConnection("http://#cgi.HTTP_HOST#/flashservices/gateway/";);
      var componentPath = MHC.services.ListingService";
      var componentPath:String = "#request.componentPath#.services.ListingService";
      </cfoutput>

Can anyone help me debugg this?
Laura
Lesley,
Remove this variable and replace it with your particular path, whatever it is.
var componentPath:String = "#request.componentPath#.services.ListingService";

to something like:
var componentPath:String = "THE.PATH.TO.YOUR.CFC";
Laura
Actually, you already wrote it, but left the old code there. Remove var componentPath:String = "#request.componentPath#.services.ListingService";
Lesley
13. Lesley wrote on July 25, 2006 at 11:50 AM
Thanks! That fixed one problem and now I have 5 more. How do you figure out these errors when they don't tell you where they are?

Here are the error messages:
5 Errors found.

Error /MHC/Test-.mxml:1147
';' expected


Error /MHC/Test-.mxml:1147
The statement 'Public' is incomplete.


Error /MHC/Test-.mxml:1221
Attribute used outside class.


Error /MHC/Test-.mxml:1235
Attribute used outside class.


Error /MHC/Test-.mxml:1273
Unexpected '>' encountered
Lesley
14. Lesley wrote on July 25, 2006 at 12:48 PM
I really need help. I tried to fix it my self and now I have 22 errors. Would anyone be willing to view my code and let me know what I am doing wrong? Let me know
Tim
Hi all,
I have recently found an issue that i need some help understanding.

I have a CFForm that calls my CFC on load and fills a data grid.

Most of the time it works fine but once in a while i can see it fill the grid on load then simply disapear.

Any idea what can cause this?

Here is my function that calls my cfc and fills the grid:
<code>
function setAttendance(UID):Void{
<cfoutput>#conn#</cfoutput>
var vacgrid = vacgrid;
var pergrid = pergrid;
var sickgrid = sickgrid;
var uatService:mx.remoting.NetServiceProxy;
var uatHandler = {};uatHandler.onResult = function(uatresults:Object):Void {

vacgrid.dataProvider = uatresults.VAC; pergrid.dataProvider = uatresults.PER; sickgrid.dataProvider = uatresults.SIC;}
uatHandler.onStatus = function(stat:Object):Void {alert("Error while gettiing Attendance Values:" + stat.description);}
uatService = connection.getService("CFC.users", uatHandler);
uatService.HR_attendance(UID);


}


<cfgrid name="vacgrid" rowheaders="false" height="130">   
<cfgridcolumn name="name" header=""/>
<cfgridcolumn name="days" header="Days"/>   
<cfgridcolumn name="hours" header="Hours"/>
</cfgrid>
<code>

thanks in advance

tim
Tim
hi Laura,
Thanks for the quick post, i can resolve this by the following:
remove the remoting and call the cfc through cfscript and assign the result the query tag of the grid.

I seem to have this issue anytime i try to load data in the onload of a form. in the past i just used a button to load the data.

I will read through the link you posted for some pointers though, thanks again

p.s. congrats on your cert!
was the test difficult?
tim
Jim
Has anyone consumed a web service using Flash Remoting over SSL? If so, any code samples woiuld be appreciated, especially on how to pull in the SSL certificate and include it in the request to the web service host. If not, any ideas on how it could be done? Thanks much, and at the risk of repeating the thoughts of others, "this site rocks!"
nsr
19. nsr wrote on January 07, 2009 at 5:41 AM
Hi,

I'm getting following error:
Service threw an exception during method invocation: No service named fileexplorer.services.fileExplorer is known to Flash Remoting.

Note: I have enabled flash remoting by uncommenting <adapter>coldfusion.flash.adapter.CFWSAdapter</adapter>

Leave your comment

Comment etiquette: As a gesture to those subscribed to this post, please keep your comments relevant to the post.

Your email address will never be displayed.
Email is gravatar enabled.Gravatar are the pictures you see next to the comments. If you like to have one, visit gravatar



Allowed tags:

<code>
All other tags will be shown as such, when in doubt, use the preview.

Leave this field empty:

Preview:

Refresh Preview
1. You wrote on