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.