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 »

How to Remove Broken or Dead Tracks from iTunes

Posted by admin on September 17th, 2011

icon 150x150 How to Remove Broken or Dead Tracks from iTunesApple has provided a script to do just this particular trick, and to make use of it you just need to do these things in order:

  1. Close iTunes if you have it open
  2. Go to the web page, right-click on it, and save the page as a file, making sure you change the extension to .js. So for instance, in Firefox, right-click on the page, choose Save page As”¦ and change the file name from RemoveDeadTracks.txt to RemoveDeadTracks.js.
  3. Open Windows Explorer and browse to the file you just saved
  4. Double-click on the file.

The script will open iTunes, and then start running through and removing dead links. In my case it took around ten minutes and correctly removed nearly two thousand links.

removed How to Remove Broken or Dead Tracks from iTunes

 

 

 

 

 

 

Another interesting tool which I haven’t tried is this one. Apparently it only works on iOs.

 

 

 

Packaging a Flex Mobile Project using Ant for Android, BlackBerry or iOs

Posted by admin on September 12th, 2011

flexIcon Packaging a Flex Mobile Project using Ant for Android, BlackBerry or iOsIf you want to package a Flex Mobile Project using Ant, you’ll first need to compile your project to get a swf. ADT is the tool need to package your application. First of all, if you want lots of information, I recommend installing the Adobe Community Help.

Remember you can also do this by creating a Release Build (right click project –> Export… –> Flash Builder –> Release Build) of your Flex Mobile Project.

Read the rest of this entry »

Compiling a Mobile Flex Project using Ant and launching the swf using the Air Debug Launcher

Posted by admin on September 11th, 2011

flexIcon Compiling a Mobile Flex Project using Ant and launching the swf using the Air Debug LauncherFirst of all, compiling a Mobile Flex Project is not the same as packaging one. Compiling is creating an swf, packaging is creating a ipa or apk file (Android or iOs). I’ll deal with packaging in a later post. If you double click on a compiled Mobile Flex Project swf, you wont see a thing. If you want to see your swf in action, you’ll have to use the Air Debug Launcher, ADL. Off course, instead of using Ant, you can also use the command prompt or Flash Builder.

Read the rest of this entry »

Problem Event Handlers in a Default Document in IIS 7 or IIS 7.5 Integrated Mode with FluorineFX Http Module

Posted by admin on September 10th, 2011

images Problem Event Handlers in a Default Document in IIS 7 or IIS 7.5 Integrated Mode with FluorineFX Http Moduleicon asp.net  Problem Event Handlers in a Default Document in IIS 7 or IIS 7.5 Integrated Mode with FluorineFX Http ModuleSome while ago I noticed that an OnClick isn’t triggered when a default aspx page is loaded (for instance browsing to http://localhost/test) but it is when browsing directly to http://localhost/test/default.aspx. The default document is set to Default.aspx, but for some reason, the click event isn’t triggered when doing a Postback.

Read the rest of this entry »

Forcing browsers to revalidate static content in IIS – Asp.NET

Posted by admin on September 3rd, 2011

icon WebCache 150x150 Forcing browsers to revalidate static content in IIS   Asp.NETHow do you force browsers to revalidate static content like an swf, xml, txt, … files? We often have this problem with customers and advise them to clear their cache. Not a very good solution don’t you think?

So how do you solve this? We could append the version of our product to the static files, so that with a new release, browsers wouldn’t hit their cache loading the file. A condition for this to work would be that the home page (default page) should always be the latest version from the server. This page would have references to the static files with version appended to them.

What about browsers asking the server if a newer version is available. In comes the must-revalidate header.

Read the rest of this entry »

Updating a Flex Mobile App on Android & iOs

Posted by admin on September 1st, 2011

flexIcon Updating a Flex Mobile App on Android & iOsWhen I was first starting to look, I thought it would be done in the same way an Air Application is updated (see here and here for more info on updating air projects). Updating Flex Mobile Apps doesn’t work this way. Quote:
The AIR update framework is only supported in the desktop profile. It is not supported for extended desktop applications (applications installed with a native installer), and it is not supported on the mobile profile (iPhone applications written with ActionScript 3.0). Check the Updater.isSupported property at runtime to see if the update framework is supported.
If you would trace out Updater.isSupported in your Flex Mobile Project, is would return false.

Read the rest of this entry »

Change Collation Sql Server 2008 Database

Posted by admin on August 30th, 2011

 

sql2008logo Change Collation Sql Server 2008 DatabaseTo change the collation of Sql Server 2008 Database, you’ll first need to drop the objects in the database that are dependent of the collation (like functions for instance). Otherwise you will get an error like this

The object ‘…’ is dependent on database collation.

Once you’ve dropped these objects, you can set the collation using this t-sql

 

 

1
2
3
4
5
6
ALTER DATABASE [dbname]
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE [dbname]
COLLATE SQL_Latin1_General_CP1_CI_AS
ALTER DATABASE [dbname]
SET MULTI_USER

After this, you’ll have to recreate your dropped objects.

Moving FileStream data to a new location or renaming it (basically the same)

Posted by admin on August 30th, 2011

sql2008logo Moving FileStream data to a new location or renaming it (basically the same)You’ll just have to detach the existing database, then rename the FileStream folder and then attach it again using following sql:






1
2
3
4
5
6
7
8
9
USE [master]
GO
CREATE DATABASE [televic-edu3-dev-one-channel] ON
( FILENAME = N'C:\Program Files\Microsoft SQL Server\...\DATA\name.mdf' ),
( FILENAME = N'C:\Program Files\Microsoft SQL Server\...\DATA\name.ldf' ),
FILEGROUP [FileStreamGroup] CONTAINS FILESTREAM DEFAULT
( NAME = N'name_FSData',
FILENAME = N'C:\Program Files\Microsoft SQL Server\...\DATA\name' )
FOR ATTACH

name_FSData will be the name of the renamed folder.

More information on other ways to do it here.

IIS Rewrite module – redirect all Http calls to Https – breaks debugging in Visual Studio

Posted by admin on August 23rd, 2011

iis7 150x150 IIS Rewrite module   redirect all Http calls to Https   breaks debugging in Visual StudioFirst you’ll need to install the URL rewrite module.  See link for detailed information on URL rewrite.

1
2
3
4
5
6
7
8
9
10
11
12
<rewrite>
    <rules>
	<rule name="Redirect to https" enabled="true">
	    <match url="(.*)" />
	    <conditions>
	        <add input="{SERVER_PORT}" pattern="443" negate="true" />
	    </conditions>
	    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" 
                    appendQueryString="false" />
	</rule>
    </rules>
</rewrite>

This rule will redirect all Http calls to Https, except calls to Https (otherwise you would end up in an endless loop). Some good info on Url Rewrite Module can be found here.

I you haven’t installed the Url Rewrite Module, your site will crash on the rewrite section.

Another thing we noticed is that debugging in VS2010/2008 with rewrite enabled (enabled =”true”) doesn’t work. Seems to be a bug. More info here and here.

pixel IIS Rewrite module   redirect all Http calls to Https   breaks debugging in Visual Studio

Copyright © 2007 Lieven Cardoen. All rights reserved.