Invoking RESTful and AMF services from Flex using WCF / MVC / FluorineFX in .NET

Posted by admin on November 12th, 2011

icon ria Invoking RESTful and AMF services from Flex using WCF / MVC / FluorineFX in .NETI’ve written a small Rich Internet Application using Flex and [dot]NET. Data from [dot]NET is returned to Flex using different technologies being MVC, WCF and FluorineFX.

In dot[NET], there are two MVC controllers, RestJsonController and RestXmlController. They both have about the same logic, but one returns Json, the other XML. There’s also a UserService with methods made public using both WCF and FluorineFX. For WCF, REST is used with both GET (WebGet) and POST(WebInvoke).

On the Flex side, REST calls are being done using URLLoader and URLRequest.  There are examples using GET and examples using POST. You’ll also see that URLVariables, Json strings or XML are used to transport data. For the AMF calls, a RemoteObject is used to call a FluorineFx gateway.

Flex only supports the HTTP Verbs GET and POST, so full REST isn’t really possible.

I created the example in Visual Studio 2010 (ASP.NET MVC 3 Web Application) and Flash Builder 4.5 Premium (SDK Version 4.5.1). You can easily open the .NET solution. The Flex source is configured to call localhost on port 53259, so make sure the .NET WebApp is started on that port (or change the Flex source code). For the Flex project, import it using ‘Existing Projects into Workspace’. Since Flash Builder has a problem with relative paths (adobe, please have a look at that), you’ll have to change some things. In the properties of the project, go to Flex Build Path, and set the Output folder to [root example project]/FlexDotNetREST/Flex, being the Flex folder under the root of the .NET Web App. Then right click FlexRest.mxml –> Run As –> Run Configurations… URL or path to launch should be http://localhost:53259/Flex/FlexRest.html.

A zip of the example can be downloaded here.

As I wife recently gave birth to a second daughter, I haven’t got the time anymore to blog a lot. So, explaining this will be difficult. But you have the source and I’ve written a lot of comment in the source it self. So check it out and let me know if it was useful.

Be sure to go and read some articles and blog posts on REST, especially the difference between low REST and high REST (lo-REST – hi-REST). A lot of developers/managers/companies think they have a RESTful api, but actually, they don’t.

http://blog.jonnay.net/archives/665-Hi-Rest-and-Lo-Rest,-two-broken-halves-of-the-tower-of-Babylon.html
http://lesscode.org/2006/03/19/high-low-rest/

WCF REST
REST in Windows Communication Foundation (WCF)
A Developer’s Introduction to Windows Communication Foundation 4

Read the rest of this entry »

XML-Problem Fluorine (SOLVED)

Posted by admin on December 5th, 2007

SOLVED WITH FLUORINEFX VERSION 1.0.0.3!

In Fluorine there seems to be a problem with sending a xml object with null as a value.

Next screenshot is taken from Charles. As you can see there’s a property Content which has null as a value. The property Content is typed to XML in Flex.

 XML Problem Fluorine (SOLVED)

The error I get is:
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.LoadXml(String xml)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3XmlDocument()
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Data(Byte typeCode, IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Data(IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Object(Int32 handle, IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Data(Byte typeCode, IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Array(IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Data(Byte typeCode, IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Data(IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Object(Int32 handle, IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Data(Byte typeCode, IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Array(IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Data(Byte typeCode, IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Data(IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Object(Int32 handle, IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Data(Byte typeCode, IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadAMF3Data(IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadData(Int32 typeCode, IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadData(IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadArray(IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadData(Int32 typeCode, IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFReader.ReadData(IApplicationContext applicationContext)
   at com.TheSilentGroup.Fluorine.AMFDeserializer.ReadBody(IApplicationContext applicationContext)

and

Root element is missing.

Screenshot from Charles:

 XML Problem Fluorine (SOLVED)

Apparently Fluorine doesn’t check whether the value is null. We’ve looked into the source code of fluorine and indeed a XMLDocument is created with null as a parameter. This throws an exception… With WebOrb this problem does not occur.
I would have to ask if the problem is fixed with FluorineFX.

Adobe Air Small Example

Posted by admin on November 27th, 2007

At work I created a small example of Adobe Air with some features in it like:

  1. Save some xml to file
  2. Read some xml
  3. Delete file
  4. Save ScreenShot
  5. Browse Directory
  6. Create Directory
  7. Using the encrypted local store
  8. Dragging a text file into application

It isn’t much and for advanced users it won’t be new, but if you’re just starting with Adobe Air, it can be of some use.

Air Package

Project Zip

pixel Adobe Air Small Example

Copyright © 2007 Lieven Cardoen. All rights reserved.