views:

248

answers:

2

When I go to http://localhost:3000/hello/sayhello, Rails outputs:

hello world!

as HTML.

But when I run this Flex remote "Hello World" app, I see a button and a textbox but it does not pick up the output of the HTTPService call to my Rails url. Any ideas why?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical"
    backgroundGradientColors="[#ffffff, #c0c0c0]"
    width="100%"
    height="100%">
    <mx:HTTPService
        id="helloSvc"
        url="http://localhost:3000/hello/sayhello"
        method="POST" resultFormat="text"/>
    <mx:Button label="call hello service"
        click="helloSvc.send()"/>
    <mx:TextInput text="{helloSvc.lastResult}"/>
</mx:Application>
+1  A: 

I'm not positive, as I can't see the XML that your service would reply with but I think it's probably one of two things:

1) Your has no element to format the request to your service. Check this out for a template...Flex 3 Help

That could either cause the request to never properly be made or your service to choke on the request and never return a result. You'd have to debug the service to see how it's handling the request.

2) Your service is returning an XML result with namespaces. In that case, you're going to need to check out Another Flex 3 Help about how to handle XML results in the e4x format.

Justin Niessner
Stupid mistake. I was calling file:///C:/public/bin/flex.html instead of localhost:3000/bin/flex.html. Thanks for your help.
Bijou
+1  A: 

I copied and pasted your code into a new Flex App, modifying the URL to point to a script I know works with Flex apps, and it worked just fine.

I also changed my server-side script to print 'hello world' with a newline, and that worked fine as well.

Your Flex code appears to be working OK with plain-text, but something is obviously not connecting between the data display and the data itself. I'm not experienced with Rails, but I wonder if your server is outputting data which cannot be parsed, and any exceptions are getting swallowed.

Here's my suggestion: change your 'sayhello' script so it simply prints a content-header and 'hello world' -- all in plain-text. Make sure it outputs in the browser, and then see if it also works in the Flex app. If it does, your Rails app is probably outputting content which needs to be parsed, as opposed to simply set to the text input. If it doesn't, you'll need to do more debugging.

BTW, I tried this with both plain-text output and XML output. In both attempts, I was able to view the content in the text-input field.

bedwyr
Stupid mistake. I was calling file:///C:/public/bin/flex.html instead of http://localhost:3000/bin/flex.html. Thanks for your help.
Bijou
Glad you got it worked out :)
bedwyr