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.
very useful and good articles !!
Great article, way more useful than anything I’ve seen on this topic. Thanks for the help!
Excelect Article, It was just was I was looking for.
I also believe this is the best way to do it.
By the way…. Is it possible for a flash web application (as above).. to be packed and used on a client localy… (I mean without IIS)
Well thanks any way…. I will test it now.
great site. excellent article on flash remoting for .NET. keep the good work going guys.
thank god, we got people like you
Great article. I didn’t even know you could an call assembly directly from flash (although you still have to pass by an aspx page).
two questions:
1- Is it really faster, or the fact that you have to pass by an aspx page anyway (gateway.aspx) makes it just as fast as accessing an asp.net page or webservice?
2- Is there any problem passing certain data types from flash to the assembly and viceversa? For example: arrays, hashtables, collections etch… Can I pass any type of variable or, for example, they have to implement the serializable interface in visual basic?
hi !!
i made the app and doesn´t work. It keeps sends the message: NetConnection.Call.BadVersion..
Anyone know what it is ?
thanks
barbara
Flash Remoting can be tricky to get running initially. I was running, ASP.NET, with Flash MX 2004 (NOT pro). My advice is this…
#include “NetServices.as”
may not work so try:
import mx.remoting.NetServices
instead. Great article, happy coding!
i have a big problem. It works fine when i’m trying to run the example to my local web server but i get an error (can’t find service-method) when i’m trying to run it to my web server.
I needed some way to get flash variables into .net..I was considering flash remoting..buit it was very expensive and i dont think my host would let me install it..so i just posted variables to a .net page and the page proccessed it..worked fine…….this is a solution only if you need to do very basic stuff…
I’ve on and off trying to figure flash remoting, now I see the light. Thanks
Excellent Sit.This is very helpful for me.
Nice article. I’ve got it running locally but not quite sure about deployment on another web server.
Questions:
1. Do you need remoting components as well as .net remoting?
2. Remoting components require the Flash install, which does not make sense on a web server?
Also .Net remoting is relatively expensive $999/CPU!
Thanks!
(VB) ASP.NET and Flash Remoting and Serialization problemo:
I am trying to bind data to a flash object:
Flash.DataSource = ds.Tables(“Return_Set”)
Flash.DataBind()
Everything is setup like the above describes, but I get the following error:
Type ‘FlashGateway.IO.ASObject’ in Assembly ‘flashgateway, Version=1.0.57934.0, Culture=neutral, PublicKeyToken=null’ is not marked as serializable.
Thoughts?
Gracias.
Anyone has issue running flashremoting on two websites on same IIS webserver. I have this issue where any call to non default website always routes to default website and returns the results. This is very weird and i have no clue why flash gateway would do this. I even seen request going to the non default website service so all my configuration parameters are correct. Please help!! it is affecting our production env and adobe is of no help so far..
hy first sorry for my english.
my problem is I write aspx page which can cominicate on local machine width flash8 remot project.I do write the code correct.when I transfer simple string variables there is no problem.but when I want to use ado .net and call some tables form sql,on flash side I have no dataset tables object to bind my flash grid.I thought perhaps I should let in my asp.net for my “bin” file writeble and readeable by every one.so I right click on “bin” file and let read and write on internet.my questione why I donat have any thing on flash side and What shoul I do.
if any one send an information I would be verymuch glad. thanks a lot …..
Wow, that’s a really complex process – and, when I tried using it, I ran into quite a few other problems. So, I built out a new open source project – I’m calling it Amf4Asmx. Simply build out a WebService, add the Amf4Asmx binaries, and add about half a dozen lines to your web config. Your web service’s asmx file automatically acts as the flash remoting gateway!
Good luck with all of your Flash and ASP.Net projects!