Working with Flash Remoting Using .NET
 
Published: 01 Aug 2006
Unedited - Community Contributed
Abstract
This article demonstrates the usage of Flash Remoting using .NET with an example to show how a Flash UI layer communicates to a .NET Application layer through Flash Remoting.
by Kr Hemendra Singh Shaktawat
Feedback
Average Rating: 
Views (Total / Last 10 Days): 36357/ 48

Introduction

Flash Remoting is a product from Macromedia Flash which works as an interface between the Flash application and your server side applications such as .NET, J2EE or ColdFusion.  The big advantage of the Flash Remoting is that you can pass live objects like XML objects to and from the server. The image below shows the overview of the Flash Remoting control flow.

Figure 1

Installation

Flash Remoting (evaluation version) is available at the Macromedia website (free to download) and the Flash Remoting component is also available at the Macromedia website for free.

There are two ways of using the Flash Remoting.  The first is to use it at your web server and the second is to use it with your Flash application development.  If you want to host an application which will use Remoting then you just have to install the Flash Remoting to your host machine. This requires that .NET framework already be installed on your host machine.

If you are developing a Flash application which will use Remoting then you have to install the Flash Remoting component on your machine.  To install the Flash Remoting component you have to have Flash MX or Flash MX 2004 installed on your machine.

You must restart your computer after you install the Flash Remoting or Flash Remoting component.  It will not ask you to restart the system, but it will not work until you restart the system.

Flashgateway.dll

Once you are done with the installation and are ready to start your first "Hello Remoting" application, you have to do a few small jobs to move forward.  While you installed the Flash Remoting it would have created a web application at "http://localhost/flashremoting."

The folder path is C:\Inetpub\wwwroot\flashremoting.  Go to this directory, open the bin and copy the flashgateway.dll and frconfig.txt to the bin directory of your .NET application.  The frconfig.txt has the licensing information in it.  We name the .NET application as MyRemoting and from now on we will refer the .NET application as MyRemoting

Gateway.aspx

Add a file named gateway.aspx to your MyRemoting directory.  This file will be empty and will not contain any code.  You can write one line as the following.

Listing 1

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

This file will be used by the Flash Remoting as the starting point to access your .NET application.

Web.config

Open the web.config file from MyRemoting directory and put the below mentioned code in the middle of the file.  This will be used by MyRemoting to refer Flash Remoting.

Listing 2

<httpModules>
<add name="GatewayController" 
type="FlashGateway.Controller.GatewayController,flashgateway" /> 
 </httpModules>

Register Flash Gateway with .NET

Add the two tags mentioned below to your .aspx or .vb file which will serve your Remoting call. For example, we will call it MyRemotingService.aspx from here onwards.  The first tag will register the Flashgateway with .NET and the other tag will be used if you put your server side code in the aspx file only.  You can add functionality to the code behind the file as well.

Listing 3

<%@ register tagprefix = "Macromedia" 
NameSpace ="FlashGateway" Assembly ="flashgateway" %>
<Macromedia:FLASH id="Flash" MACROMEDIA:FLASH MACROMEDIA:FLASH>
</Macromedia:FLASH>

We are done with the configuration, so what is next?

Now that we are done with all the setup for the Flash Remoting, we can start writing code for the Flash to communicate with our server application using Remoting.  We will create a Flash file which will communicate with the .NET Remoting server.

We will create a Flash application which has two sections.   One which takes user input for the user's first and last name and sends those to the server as the XML object server will concatenate the first name and last name and return the full name to the user as an XML object.  Another section will just take the user request and return server time in string format.

For this application at Flash end, we have one “MyRemoting.fla” and one external ActionScript file named “RemotingWithDotNet.as,” which contains the code for Flash to do Remoting.  At the server end we have a VB project, “MyRemoting.vbproj,” and “MyRemotingService.aspx.vb” to serve the Remoting calls as well as few other .NET created files.

We start with the Flash part first.  Create a Flash document and name it "MyRemoting.fla."

Figure 2

 

Here is the code that goes into the action layer of our .fla file.

Listing 4

#include "RemotingWithDotNet.as" 
_root.btnFullName.onRelease = function(){
var sXML:String = "";
 var oXML:XML;
if(_root.txtFirstName.text == "" || _root.txkLastName.text == ""){
_root.lblFullName.autoSize = "left"; 
 _root.lblFullName.text = "Please type your first name and last name."
 _root.status.text = "";
}else{ // Make XML string
sXML += "<root>";
 sXML += "<firstname>" + _root.txtFirstName.text + "</firstname>";
 sXML += "<lastname>" + _root.txkLastName.text + "</lastname>";
 sXML += "</root>";
// Create XML object
oXML = new XML(sXML);
 _root.status.text = "Connecting to the server...";
// Make a Remoting call to the server 
_global.oRemoting.ConcatenateName(oXML);
}
}
_root.btnServerTime.onRelease = function(){
_root.status.text = "Connecting to the server...";
// Make a Remoting call to the server 
_global.oRemoting.GetServerDateTime();
}

The #include "RemotingWithDotaNet.as" does the inclusion of our external file.

The other two functions are called on the different button click.  The root.btnFullName.onRelease() picks values from the input boxes, prepares the XML object and makes a request to the Remoting server.

The function _root.btnServerTime.onRelease() does not need any XML to be sent, so it makes the server call as soon as the button is clicked.

Here is the code from our RemotingWithDotNet.as file.

Listing 5

// This will be used for getting Remoting services.
#include "NetServices.as" 
_global.oRemoting; // Global Remoting object, will be used to call Remoting services.
function init() 
{
       if (this.inited != undefined) 
       { // init is not required.
       return;
} else { 
       
       this.inited = true;
       NetServices.setDefaultGatewayUrl("http://localhost/myremoting/gateway.aspx");
       gatewayConnnection = NetServices.createGatewayConnection();
//This is our default relay interface     
defaultService = "myremoting.MyRemotingService";
       _global.oRemoting = gatewayConnnection.getService(defaultService, this);
}
}
// RESULT FUNCTION FOR: oRemoting.ConcatenateName()
function ConcatenateName_Result(result) 
 {
       _root.status.text= "";
       result.ignoreWhite = true;
       trace("result :: " + result);
       _root.lblFullName.autoSize = "left"; 
       _root.lblFullName.text = "Hello " + result.firstChild.firstChild.toString(); 
 }
function ConcatenateName_Status(error) 
 {
       _root.status.text= "ERROR: " + error.description + newline;
 }
// RESULT FUNCTION FOR: oRemoting.GetServerDateTime()
function GetServerDateTime_Result(result) 
 {
       _root.status.text= "";
       result.ignoreWhite = true;
       _root.lblServerTime.autoSize = "left";
       trace("result :: " + result);
       _root.lblServerTime.text = result.toString();
 }
 
 
function GetServerDateTime_status(error) 
 {
       _root.status.text= "ERROR: " + error.description + newline;
 }
init();
 stop();

The first line of the code #include "NetServices.as" includes the file NetServices.as that will provide us the implementation of Remoting functionality.  The init() function instantiates the Remoting object.  In our case that is "_global.oRemoting."  We are done with the Flash side code; here is the server side code which will serve our Remoting requests.

Listing 6

Imports System.Web.UI
 Imports System.Xml
Public Class MyRemotingService
 Inherits System.Web.UI.Page
'--- This function accepts a XML object with two child nodes as first name and
 '--- last name and returns the full name in one node.
Public Function ConcatenateName(ByVal oXMLIn As XmlDocument) As 
 XmlDocument
Dim oXMLOut As XmlDocumen
 oXMLOut = New XmlDocument
 oXMLOut.InnerXml = "<root>" & _
 oXMLIn.FirstChild.ChildNodes(0).InnerText & " " & _
 oXMLIn.FirstChild.ChildNodes(1).InnerText & _
 "</root>"
 Return oXMLOut ' return the new XML object.
End Function
Public Function GetServerDateTime() As String
Dim sServerDate As String
       sServerDate = Now().ToLongDateString.ToString & " " & Now().ToLongTimeString.ToString
       Return sServerDate
End Function
End Class

This class has two functions: ConcatenateName() and GetServerDateTime().  We can call these from our Flash application.

How application works

When we make a request to the Remoting server from Flash it processes our request and returns the result back to Flash.  Flash Remoting uses call back functions to handle the server reply. These functions, as present in the code above, use the same function name we call to process our request with suffixes as _Result for the Result and _Status to handle any error if it occurred at the server while processing our request.

So when everything goes well and the server returns as expected, the call goes to _Result call back function and if it does not, the call goes to the _Status callback.

Benefits of working with Remoting

This gives us the ability to connect to and read live data, XML, and consume Web services or business logic at application servers such as .NET, J2EE or ColdFusion.

Downloads

Questions

Can I change the "Gateway.aspx" to another file as this file is a blank file?

Can I access multiple Remoting services from one Flash application?

Can I keep Remoting service responses (*_Result and *_Status) to another file?

Can I rename "xyz_Result" and "xyz_Status" to "xyz_somethingelse?"

If you know the answers to these questions, congratulations you know the concept of Flash Remoting!  You can write your answers or queries to me and I will get back to you.

Summary

So, the Flash Remoting gives us such benefits as:

·         The flexibility to connect to any middle tier application developed in .NET, Java, ColdFusion and PHP.

·         Complete UI logic can be shifted to client side as the server has fewer loads and performs better.

·         Separates the UI from middle tier and the backend, so all can be independent.  If have your Remoting middle tier in .NET today and tomorrow you want to switch to Coldfusion, you can do it without touching the UI at all.

In short, the Flash Remoting gives us the beauty of rich Internet UI and the power of web application with a great user experience.



User Comments

Title: nfl jerseys cheap   
Name: NIKE NFL jerseys
Date: 2012-07-02 10:09:06 AM
Comment:
http://www.jersey2shop.com
http://www.cheapjersey2store.com
http://www.jerseycaptain.com
http://www.yourjerseyhome.com
We are professional jerseys manufacturer from china,wholesal.cheap nike nfl jerseys, mlb jerseys, nhl jerseys,nba jerseys and shoes
Cheap NFL,NBA,MLB,NHL
,heap jerseys,2012 nike nfl Jerseys,nba jersey and shorts,oklahoma city thunder jersey,official jeremy lin new york knicks jersey,NFL Jerseys Wholesale,blake griffin jersey blue,NFL jerseys For Sale online.All Our Jerseys Are Sewn On and Directly From Chinese Jerseys Factory
,Wholesale cheap jerseys,Cheap mlb jerseys,]Nike NFL Jerseys,Cheap China Wholesae,Wholesale jerseys From China,2012 nike nfl Jerseys,Jerseys From China,,2012 nike nfl Jerseys,Revolution 30 nba jerseys,jersey of nba chicago bulls direk rose ,nfl jerseys,green bay packers jerseys wholesale,Buffalo Bills nike nfl jerseys sale,good supplier soccer jerseys,cool base mlb jerseys,Revolution 30 nba jerseys,2012 stanley cup nhl jersey,
We are professional jerseys manufacturer from china,wholesal.cheap nike nfl jerseys, mlb jerseys, nhl jerseys,nba jerseys and shoes. www.yourjerseyhome.com
Title: sdsds   
Name: sdss
Date: 2012-05-31 3:03:21 AM
Comment:
hai
Title: Nice Tuts   
Name: Simon
Date: 2009-08-26 10:24:40 AM
Comment:
Thanks a lot as this tut helped me for Flash remoting. a good article.
Title: Help   
Name: Venus
Date: 2007-12-10 1:28:10 AM
Comment:
CanI use Flash remoting in .Net Windows application?
Title: help   
Name: JayLor Juan
Date: 2007-02-26 7:52:21 PM
Comment:
Hi

I want to learn more on how to make a site using dreamweaver.
Can you please send me a tutorials on how it works? How to use? send me on this e-mail-->jaylor_juan@yahoo.com
Thanx
Title: How to change the function name   
Name: Dennis
Date: 2006-12-01 7:30:17 AM
Comment:
How can I change the name of the function used here.When i try to change the function name
Title: more example for flash remoting with ASP.Net   
Name: bailemad
Date: 2006-10-29 1:31:06 PM
Comment:
i would to put more examples for these practice about how to use sql server with flash remoting,flash 8 and ASP.NET.
extually, how to link a combo box with a list box
please i would like these practice
bailemad
Title: Flash 8 remoting with .net   
Name: Haris
Date: 2006-10-16 4:17:15 PM
Comment:
Hello I have download your code and open your flash files in flash 8 but I am not able to run the code although i copy your folder in my wwwroot folder.can you please help me
my email is syed@voicenow.com
Title: Re: Help!   
Name: Hemendra Singh
Date: 2006-09-18 9:47:15 AM
Comment:
Hi,

Could you please tell me the steps you have taken and the versions of SW, Might be some thing missing. So just drop me an email and I will be back to you with suggestion.

Good Luck

Hemendra Singh
Title: help!   
Name: Marco
Date: 2006-09-18 9:32:38 AM
Comment:
I dunno why the gateway is not working I upload your example and doesn´t work
Title: Remoting on .NET 2.0   
Name: Ryan Belisle
Date: 2006-08-28 12:05:14 PM
Comment:
Have you been able to get Remoting to work with .NET 2.0?
Title: rating   
Name: guest
Date: 2006-08-02 8:15:53 AM
Comment:
very good

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-24 8:18:35 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search