11 Replies Latest reply on Jan 11, 2007 6:59 PM by ntsiii

    Flex with ASP.NET?

    ac361 Level 1
      Hi. I've heard that you can use Flex 2.0 with ASP.NET. Does anyone know of any articles/links that can help in this regard? I know support for .NET is coming in a future release of Flex, but I've also heard that there are ways to get the current version working with ASP.NET. Thank you
        • 1. Re: Flex with ASP.NET?
          ac361 Level 1
          I'll expound on the question: The applications we write are database access, not much file system access. I'm new to Flex but have a few years experience with .NET. I'd love to build a simple ASP.NET to just show off Flex's power to the folks in my department and division. I don't have the Flex Builder tool (wish I did!), but would like some guidance on how to start and get some simple stuff showing on a page. Thank you :)
          • 2. Re: Flex with ASP.NET?
            ntsiii Level 3
            Ok, lets get some basic concepts straight.

            Flex is a client-side presentation technology. It produces a Flash SWF file that contains all the client logic necessary to render a user interface. The flash swf is instantiated in html using the object and embed tags.

            That HTML wrapper can be produced by any server process you want: static htm page, JSP, PHP, ColdFusion, ASP.Net, whatever. It is just html to the client browser. This is the first possible point of integration with asp.net.

            You can put as much logic on the client as you want, but sooner or later you are going to need to communicate with server-based logic or resources, like database or file system or business logic. Flex does this using one of three RPS protocols: WebService, HTTPService and RemoteObject. RemoteObject is a Java-based technology, but both WebService and HTTPService can be used with many other back-end technologies, like .NET. I am personally fond of HTTPService, since so far I have had control of both the server and client ends and do not plan on making my service publicly available so I don't need SOAP.

            By the way, you can get Flex Builder on a 30 day trial.

            • 3. Re: Flex with ASP.NET?
              ac361 Level 1
              Thanks, Tracy. That is a very excellent explanation :)
              I didn't know about the HTTPService. I'm not interested in making the service public so that's the way to go. Now I've got to look up the ASP.NET HTTPService and see how that's done.

              Your expertise and time are much appreciated.
              • 4. Re: Flex with ASP.NET?
                ntsiii Level 3
                It is way easier than you think. I wish I had a simple example, and maybe will try again, but this is how I do data integration in a nutshell:

                I have a single aspx page that Flex app calls via HTTPService
                this page never returns html, only xml, so I set :
                <%Response.ContentType = "text/xml"%>

                In the code-behind vb class, in Page_Load, I check the request for an "action" parameter that tells the page what to do:
                gsAction = Utility.nullHandler(Request("action"))

                Then a case statement routes the request to the correct Sub procedure. Depending, those sub procedures call out to various classes to do their work, then bundle the returned data into an xml string and retunr it to Flex here is an example:
                Private Sub listWakeupCalls()
                Dim sRoomNum As String = Utility.nullHandler(Request("roomnum")) 'get any expected data from the request
                Dim sXML As String
                If (sRoomNum.Length > 0) Then
                sXML = WakeupClient.getWakeupCallXML(sRoomNum) 'call the functionality, which always returns xml with at least an <ltroot> node
                Else 'create an error xml string
                sXML = "<ltroot><ltstatus status=""error"" action=""listwakeupcalls"" statusdescription=""request arg: 'roomnum' was not provided"" /></ltroot>"
                End If
                LogEvent.logEventEntry("td_ghost_gcrs", "TwelveData", "Ghost.listWakeupCalls", "info", "RoomNum: " & sRoomNum & " xml: " & sXML)
                Response.Write(sXML) 'send the xml to the Flex client
                End Sub

                I hope that helps. Post back with any specific questions.


                • 5. Re: Flex with ASP.NET?
                  Graeme Harker Level 1
                  There are some code examples on my Flex.NET blog
                  • 6. Re: Flex with ASP.NET?
                    ac361 Level 1
                    Thank you for the answers, ntsiii and sparky1962. The detailed code example is wonderful! Thanks, Tracy :)
                    I want to get started on that as soon as possible and start doing Flex. I searched high and low for the site that has Flex .NET info; thanks for sharing that, too :)

                    Your support and encouragement is much appreciated. Sorry I couldn't reply earlier today. Things got hectic.
                    • 7. Re: Flex with ASP.NET?
                      ac361 Level 1
                      Hi, all. Is it possible to extract the values from a Flex form and send those values to a database? I'm using an ASP.NET 2.0 app to generate the XML (with ContentType="text/xml" for the page). I'd like to get the values from the form elements and send back to the ASP.NET app, so it can then talk to the database on the backend. Your help is much appreciated. Thanks.
                      • 8. Re: Flex with ASP.NET?
                        ntsiii Level 3
                        Yes, but there is no automatic way to package up all of the elements in a container. a Form is just a cotainer.

                        Have the change or click events of the controls update a central data structure like an XML. When ready, you can sent that XML to the server.

                        • 9. Re: Flex with ASP.NET?
                          batmitra Level 1
                          i have one question
                          lets says i have a database, which i query for an employee, but the result was null, which means i didn't find what o was looking for.
                          My question is,How do we tell Flex that the result was 0, and show it on an alert box?

                          • 10. Re: Flex with ASP.NET?
                            Graeme Harker Level 1
                            Well, it depends how you're passing the results of the query back to the Flex application but if you're using Flex's HTTPService component then the lastResult property of the HTTPService object will be castable to an object that implements the IList interface, at which point you just query the length property. If it's zero, do an Alert.show()
                            • 11. Re: Flex with ASP.NET?
                              ntsiii Level 3
                              Except don't use lastResult, that is intended for binding expressions. Instead, pass the "result" into the handler, and do:
                              private function onResult(event:ResultEvent):void