Category Archives: Architecture

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

Rich Internet ApplicationsI’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

Continue reading

where-does-our-time-go-queue-queuing-people-standing-in-line-5804633

MSMQ – Basic Console application testing some basic functionality

Currently I’m doing some r&d on MSMQ and how to use it in an asp.net application. I started with these two links which explain the basics of MSMQ:

I created a small .NET Console Application to test out some of the examples myself. It’s basically a lot the same code (some of it is exactly the same), but it made me easily change some settings to check how they worked together. Especially transactions interested me because I’ll need them for my final code in our product.

This is the source project: MSMQ Basic – TryOut

Next is the code. I added explanations in the code itself. But you really should read the MSDN documentation as it is very clear. I haven’t tried out journaling yet because you need two computers to test that, so I’ll do that later on @work. Next up on r&d is MSMQ support in Spring.NET and after that checking a JMS (Java Message Service) implementation (and it’s integration in Spring.NET).

Continue reading

Memento Pattern

Yesterday I tried to implement Undo functionality with Command Patterns. The Memento pattern can also be used to do this. So what is the difference between the two?

Well, with Memento pattern the state of an object (the originator) is being stored by a Caretaker class. So if it’s possible to Undo with returning back to a previous state, use Memento pattern. Sometimes however, the originator is too complex to save each time its state (it could be a composite for instance). In that case the undo facility can use commands. Whenever an action is received a compensating action is set up and stored in the undo facility.

Example in Flex of Memento Pattern. I haven’t added too much comments because the code and example should speak for itself.

thx, Lieven Cardoen

Related: Command Pattern Undo Functionality

Pattern for Undo functionality

Yesterday someone asked me how to implement Undo functionality.  I knew there was a pattern commonly used for this, but couldn’t remember it. In my common sense I would keep track of previous states of properties (or actions). After some search I found that Command pattern is a good choice to implement the Undo functionality.

With some online examples I implemented an undo functionality pattern in Flex. Doing such an exercise makes me understand the theory behind it better.

Here’s the first example. Right click on the swf to view the source.

Next is implementing redo functionality in it. In a third step I’ll try to make some things more generic so I can use it easily in our product.

What would also be interesting is to make the example work in a way that only whole words are undone instead of single characters. I’ll also look into that later on.

thx, Lieven Cardoen

Related: Memento Pattern

Techdays

Rounding up last month – Pex, Mocks, NSK, CHESS, Linq, Silverlight, TechDays

It has been a while since I wrote anything, but that’s mainly because we have a new family member… Romée, a beautifull daughter, six weeks old!

dsc_0220

Back to the usual stuff. What have I been doing the last month. Well, there were Techdays, on which I wrote a few things but I still need to round that up. I also went looking for best practises to build a .NET layered application. The Northwind Starters Kit was most usefull for this. And there were also the Mocking frameworks, which seemed very complex at first (like everything in it it appears to be very simple afterwards…).

Pex & Chess

Very inspiring talk on Techdays about automated White box Testing and finding and reproducing Heisenbugs in concurrent programs. There was an example of a team that got a report of a bug that had to do with concurrency they just couldn’t reproduce. They let CHESS do its thing and in less than a minute they found the bug. Very impressive.

Mocking frameworks

In my Flex projects I had already used mocks, but they weren’t exactly mocks… Now that I began exploring .NET architecture, I really found out what these mocking frameworks are about. And they impressed me. Certainly the fact that if you want to use mocking frameworks you need good design, is interesting. To me it seems that a mocking framework is very good to test your base design (framework), if it’s done using principles described in books like Patterns of Enterprise Application Architecture or Domain driven Design (or others).

Northwind Starters Kit

This Kit has helped me a lot in having a good example of how you could implement a good .NET layered architecture. I also checked out DinnerNow, but things went wrong when installing (and I just hate that — if you’re limited in time, you don’t want to go looking why this or that doesn’t install properly. If I have to make installers for cd-roms, they need to work…). I’m now implementing a very small part of a product of ours with this NSK example. I will also try to check out a few mocking frameworks and a few IoC frameworks and integrate them in this small part. The best way to check out this NSK is to checkout the svn repo.

SilverLight

A few good presentations on SilverLight at TechDays. I certainly think they got a lot of advantages over Flex, but it will still take a lot of time. What really annoys me a lot is the arrogance by which some presentators present SilverLight. Anyway, their CLR seems a lot more robust that the Flash Player, but so far I haven’t seen business solutions being created with SilverLight. So I’m actually waiting a little bit on such examples. Now it’s always very simple examples or interactive sites that really don’t have to deal with a lot of data. There was a neat example of a Chess Game where they let a Javascript engine play against an .NET engine (SilverLight). SilverLight always won and could precess a lot more paths/second. A colleague of mine ported the engine to Flash, and could then compare Flash against .NET. The original game can be found here. The blog post from my colleague here. After the presentation on this, I asked a Microsoft guy how Flash would compare to this. He told me you couldn’t do this in Flash. Mmmm.

Linq

Very good presentation on Linq! Now I now what Monads are (look them up in Wikipedia). I haven’t used Linq all that much, but loving maths I’m interested in how this is implemented. The presentator quickly went deep into the subject which was fantastic (but also sometimes a labyrinth). Also the possibility to extend Linq to any other sort of data is great.

Oslo

Seemed very interesting, but I’ll have to check more examples to know how this could be used in every day development. The custom parser seemed very powerfull if you would need to convert data to another format.

Cheers, Lieven Cardoen

TechDays Day I: Software + Services: The convergence of Saas, SOA and Web 2.0

Very motivational and interesting presentation, especially because of the different existing examples around on the net.

First of all, everything is about data and how to bring it to clients (whether they are users or other applications) and bringing software above the level of a single device.

An interesting book that was talked about is “Place to Space” by Peter Weill & Michael R. Vitale. “Place to Space” deals with the business models an e-business can adopt. The central idea of the book is that there are 8 atomic business models that exist. It’s a very interesting way to model for example cash flow, product delivery, …

Cool examples:

Eve Online : Very impressive game.
Photosynth I had seen this before and I really will try to make one myself.
British Library Well, this is less fantastic to me in terms of GUI, but it is a enormous access to data.
WorldWide Telescope Very impressive!
Yosemite Extreme Panoramic Imaging Project Also very impressive. Click on result by the way.

The Cloud was off course a topic in this presentation with the .NET Services and SQL Services. Will look into these in the coming weeks.

Lieven Cardoen

TechDays Day I: Identity & Cloud Services

In this presentation I kinda got lost a couple of times. I hoped to see some examples of Azure in practice, but this wasn’t really the case (except one example that I hope to see soon on the blog of Vittorio Bertocci).

My interest was more in Azure for Web Developers. Azure Service Platform is designed to help developers create, deploy, manage and distribute web applications and services. Also, if you have a lot of traffic and load, you’ll pay more, otherwise you’ll pay less. Hosting is provided for you.

I’ll just need to try it out. I know WebORB has managed to run their applications in the Cloud, so it shouldn’t be a problem.

Quote:

Next time you’ll want to build something in house, ask yourself:
Do I really need a generator here, or could I just connect a plug?

Link to Azure Services Platform

thx, Lieven Cardoen

TechDays Day I – Architecture: The good, the bad and the ugly

I was a little bit too late for this session, but I did manage to grab the most important things. The presentation began with a lot of antipatterns and then followed with good patterns. Most of the things were rather obvious. A really funny thing was an example of the MSSQL database behind one of the first versions of SharePoint. There were like hundreds of tables with absolutely no relationships between them. Instead they created some 500 stored procedures that needed to take care of the integrity of the database… Guess there are also ‘disaster developers’ working for Microsoft.

Anti patterns

McKinsey Syndrome

  • We know it all, we don’t nee to listen…
  • They don’t know what they really want…
  • Just a cookie-cutting re-delivery…

Opposite Anti-pattern: Obedient Butler

Napkin Doodle

  • It was so straight-forward requirement…
  • We agreed on all req’s during lunch…
  • Light projects don’t need heavy process…

Opposite Anti-pattern: Documentation Overkill

Measure abuse

  • Each req must have success metrics…
  • If you can’t measure it, it is not there…
  • We need binary criteria of achievement…

Opposite Anti-pattern: Softie-softie

Start small, grow fast

  • Just for couple of users first…
  • Prototype, patch-up, deploy…
  • We’ll add scalability later…

Opposite Anti-pattern: Let’s Go Global NOW!

Best-of-breed

  • All the best tools (best database, best webserver, …) but no communications beween them…

Opposite Anti-pattern: Vendor Lock-in

YAGNI (You Ain’t Gonna Need It)

  • I’m sure nobody needs this requirement…
  • I bet this one is totally irelevant…
  • Too low on priority list…

Opposite Anti-pattern: Analysis Paralysis

Reinventing the wheel

  • We can do it better. Much better…
  • It would be boring to re-use the old stuff!
  • I trust my code and my code only.

Opposite Anti-pattern: Golden Hammer (One thing that solves everything… everything must be a nail…)

Sales-driven Design

  • We sold it, you just implement it…
  • Trust me, I’m technical too…
  • Does it work? Shut-up then…

Opposite Anti-pattern: Technological Purity

YAFL (Yet Another Fine Layer)

  • Architecture is simplicity, not intellectual violence

Good patterns

  • Modularity (degrees of freedom)
  • Open-ended systems (specific vs generic). Move from Application-Specific (solution) to General-Purpose (Infrastructure)
  • Build to grow (Wu Wei)
  • Identifier, Format and Protocol (back to the roots)
  • Middle-out Architecture (Wide range of implementations, Minimal Spec and Wide range of uses)
  • Poor-man Application Model
  • Web-Oriented Architecture
  • Lines matter more than boxes (Protocals are inherently stable, applications are not)
  • Dependency Inversion (Fold knowledge into data so program logic can be stupid and robust, What needs to be easy to understand and change goes into data, What will be stable goes into code). Data should depend on code, Code should not depend on data.
  • New-age development with MetaData and Model-Driven Design
  • Virtual worlds, virtual rules

Advanced Design Principles

The Open/Closed Principle (OCP)

A module should be open for extension but closed for modification.

Liskov’s Substitution Principle (LSP)

Subclasses should be substitutable for their base classes.

The Dependency Inversion Principle (DIP)

High-level modules should not depend upon low-level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.

POD component – Dashboard

Yesterday I was looking for a way to show multiple statistics next to each other. I had a component in mind that could contain Panels. The Panels would have to be divided over the available space. If there was one Panel, it would get all the space, with two Panels the space would be divided in two, … Also you need to maximize, restore and minmize the Panels.

Thx to Tom Van den Eynde from VDE Projects I found a very nice example of such a component.

Here is the link: http://www.adobe.com/devnet/flex/samples/dashboard/dashboard.html. The Panels are also draggable.

I haven’t begun to use it but I’m sure this will be a great example to start from.

Thx, Lieven Cardoen