.NET Flash Remoting: ASP.NET, ADO.NET, Webservices or Assemblies?

Spent some quality time with SQL Server 2000, .NET Assemblies, Flash Remoting and the DataGrid Component last night and this morning. My current project at work involves setting up a Flash client (which I won’t be writing), to talk to .NET via Flash Remoting. We’ll also be using ASP for other clients so the business logic that lives in multiple stored procedures on the database server can be accessed by both ASP and C#.

Anyway, last week I spent a couple hours getting up to speed on setting up .NET Remoting, specifically I wanted to know which .NET technology would be best suited to the job (you can use ADO.NET, ASP.NET pages, Web Services and Assemblies). If you download Flash Remoting for .NET and then install the Flash Remoting executable, you’ll get a subdirectory off of inetpub\wwwroot\ called ‘flashremoting’, which contains an example of the first three options mentioned above written in VB and C#. Long story short, using ADO.NET, ASP.NET pages or ASP Webservices didn’t strike me as the ‘best’. The ADO.NET version requires that you use register the flashgateway dll within your ASP.NET page like so:

<%@ Register TagPrefix=”Macromedia” Namespace=”FlashGateway” Assembly=”flashgateway” %>

and the code behind for the above page also is tightly coupled to Flash:

public class CustomerInfo : System.Web.UI.Page
  {
    //Define Objects needed for CustomerInto Class
    protected FlashGateway.Flash Flash;

The ASP.NET page looks like this:

<%@ Register TagPrefix=”Macromedia” Namespace=”FlashGateway” Assembly=”flashgateway” %>
<%@ Page language=”c#” debug=”true” %>
This line is available only when the page is viewed through a web browser.
<Macromedia:Flash ID=”Flash” runat=”server”>

The Webservice example doesn’t presupposed it’s going to be used by Flash, which IMNSHO is a good thing. And while a Webservice is an excellent way of exposing your business logic to various non human clients, performance will never be as fast as a non-webservice call, which leaves us with Assemblies. Why didn’t Macromedia offer an Assembly example? 🙂

An assembly lives in the {applicationroot}/bin folder off your website and can be used by any other client. It doesn’t presuppose that it will be used with Flash (which means I have loose coupling of my apps and I can probably reuse this business logic anywhere else I want) and performance will be markedly better than a webservice (when not using the Flash Remoting client, which doesn’t *really* make a SOAP call to the Webservice). Anyway, for my own sake, here are my .NET Flash Remoting setup notes (which came from http://www.jasonmperry.com/articles/YahooQuoteTicker.aspx:

1) download and install .NET Flash Remoting

2) download and install Flash Remoting Components

3) copy the flashgateway.dll (which was probably installed into \inetpub\wwwroot\flashremoting\bin\) into the site you’re working on: \wwwroot\yourapplication\bin\

NOTE: /yourapplication/ must be marked as an ‘application’ within IIS

4) add
<httpModules>
  <add name=”GatewayController” type=”FlashGateway.Controller.GatewayController,flashgateway” />
</httpModules>

to your web.config file in /yourapplication/

5) create an empty file called ‘gateway.aspx’ in /yourapplication/

<%@ Page %>
<!– This file is intentionally blank. –>

6) write your Assembly in C#/VB.NET, compile and then publish it to the /yourapplication/bin folder where it should be happily co-existing along w/ the flashgateway.dll file you copied to this folder in step 3.

7) Open up FlashMX, do your dee-sign thing and then include something like in the Flash movie:

#include “NetServices.as”

////////////////////////////////////////////
// Inits Web Service
////////////////////////////////////////////

//creates connection to ASP.Net web service
//should never ever run more than once!!
if( init == null )
{
  //insures this code block is only run once
  init = true;

  // point flash to the flash remoting gateway
  NetServices.setDefaultGatewayURL(“http://localhost/yourapplication/gateway.aspx”);
  gatewayConnnection = NetServices.createGatewayConnection();

  // register your service w/ flash, substituting com.packagename.Classname for the package and name of the C#/VB.NET class you wrote and have installed to /yourapplication/bin/
  myService = gatewayConnnection.getService(“com.packagename.Classname”, this);

}

// call a method on the service you’re written
myService.getProducts();

….

Hope that helps someone!

Further resources:

Flash Remoting Docs: [source]
ASP.NET assemblies in Flash: [source]
Flash Remoting Sample Applications: [source]
Flash Remoting Development Center: [source] (where is the .NET category BTW? how about some more .NET examples MACR?!!?)
Viewing Flash Remoting log entries: Flash Remoting MX writes error messages to the flash.log file in the local assembly cache. You can change the log file settings in the Windows Registry. The Flash Remoting registry keys are located at HKEY_LOCAL_MACHINE\SOFTWARE\Macromedia\Flash Remoting\1\Registration.

XMLBeans

Follow up to my post about JAXB, BEA just released a beta version of XMLBeans, which, in marketing speak “.. is the first solution that successfully merges the power of the XML API approach with the simplicity of the XML marshalling approach to provide unprecedented levels of both robustness and ease-of-use.

SXSW festival by Heath

Heath Row blogged the SXSW festival. If you didn’t get to go, it looks like Heath has typed up every word spoken during the entire shindig. Especially interesting was his write up of Richard Stallman‘s discussion: “Copyright Vs. Community in the Age of the Computer Networks“.

In 1983, I reached the conclusion that for people to use computers freely, they needed to have access to free software and be able to use it freely. You should have the freedom to use software once you’ve got a copy. There are three freedoms. Freedom 0 is the freedom to run the program. Freedom 1 is the freedom to help yourself by studying the program and changing it to suit your needs. Freedom 2 is the freedom to help your neighbor by giving them a copy of the software. Freedom 3 is the freedom to help build your community by working together to build that software.

Why the Web Matters

David Weinberger gave the opening presentation at SXSW a couple weeks ago, I didn’t get to go but I got the jist of his presentation via his email newsletter (which was packed w/ interesting btw, sign up now!). He called it “Why the Web Matters”:

I have 10 times as many friends as I used to. I know 100 times more people. I have 1,000 times more people I can call upon for help, support or a well-deserved kick in the ass.

My friendships last longer. I’m still in touch with people I worked with in the ’80s even though
in the real world, I forget relationships the way I flick crumbs off a table.

Not only is there a gazillion times more information available, we expect the chain of information never to end. Whatever the topic, we expect to be able to browse indefinitely.

Every conceivable topic has its own site and its own cluster of people around it.

If I don’t trust the voice of authority, all I have to do is turn my head a quarter turn to hear the voices of those whose stories that voice is re-telling.

Our kids take it for granted that they can publish to the entire world without first having to get their writing accepted by a publisher.

Everyday I receive email from people I’ve never met pointing out amazing, funny, heart-breaking and sometimes merely amusing sites.

Those who we know by reputation are no longer inaccessible on their own private Olympus. It’s likely we can find their email address. And when we write, we may well get an answer.

The largest network of human creativity and history’s best operating system have both been created by distributed networks of people who never once have sat in on a weekly status meeting about the projects.

We are learning that the world consists of people joined by shared interests rather than simply countries divided by patrolled borders.

re: The conversational enterprise

John writes that “… blogging is almost recreational — it’s hard to point to a solid return-on-investment for the time.” I don’t work at a large enterprise so I can’t comment on ROI at the business level, but personally, blogging is great way of saving and then reusing the knowledge you gain on a daily basis (how to use rsync, getting servlets to reload…). How many times do you think to yourself “I remember doing that once, but where did I write it down?” I used to use Outlook for this, but searching your Outlook hierarchy is excruciatingly s l o w. If you have a blog, you probably wrote about it in your blog, which you can then use full text searching to retrieve in a matter of seconds. I can get my job done faster. That’s ROI. Course, the same thing applies to people that I work with. I’ll get an email from someone about JSP Coding Standards and I can point them here because I remember writing about it. Other people get their job done faster.

XML to CFC Mapping Tool?

Ray asked during our developer meeting today if .NET had any tools like JAXB. The Soapsuds Tool looks to be similar, although it certainly doesn’t appear to have as many features. But I think Ray was asking the wrong question. A CFC is approximately equal to a JavaBean in structure, so where JAXB for ColdFusion? Who’s creating a CFC generation tool? CFCZone.org would be the reasonable place to start but they’re still in startup mode (ie: no content). XML parsing is certainly easier in CF than it is in Java, so maybe it’s a moot point, but nonetheless it could be helpful to have a XML to CFC generator.

Now with 50% less caffeine!