The following example will help you connect your Flex application to C# code via FluorineFx.While this is easy, lack of proper example makes the job tough for beginners like me. Since after googling and searching the web I was finally able to do it, I thought it would be good to post an example.
The following example will assist you with communicating with C# code using Remoting. The Flex application will create an object of the remote class and execute a function of the remote class.
Since Flex uses AMF and C# uses SOAP for remoting we need a gateway like FLuorinFx (or WebORB).
Requirements :
You will need the following softwares.
1. Adobe Flex 3.0 (or above)
2. MS Visual Studio 2005 (or above)
3.FluorineFx (available at http://www.fluorinefx.com/download.html)
Create an empty solution in VS 2005. Add a FluorineFx class library and a FluorineFx website to the solution. Implement the following class in your class library.
namespace MyDemoLib
{
[RemotingService]
public class Math
{
public Math()
{
}
public int add(int x,int y)
{
return x + y;
}
}
}
Build the project and run it. The class library is automatically built and added in the references section of the website. If you create a different project for the two then add the dll of the class library manually.
Now comes the Flex part.
Create a simple project in flex.
I named it "DemoProjectFluorine". Since we are taking a simple example we will design the main application page to accept the user input. If you have decided to make a more complex project the you would probably make a custom mxml component and then use it in the main application page.
The code is as below.
In the above code we create a RemoteObject and use this object to call the remote method.
One important point is to include a configuration file in the flex project that helps to resolve the uri to the appropriate website ( which we created and ran before). Also include this file in the Flex compiler settings.
You can do this by a right click on the flex project -> properties ->Flex compiler and include the path to this configuration file in the additional compiler arguments.
"-services "services-config.xml" "
The configuration file is as below.
Please note the endpoint URI for the above is at port 1425, please change it to the port on which your ASP.NET website runs.
All is done now you are ready to go.
Just for fun add a breakpoint to the method in the website and see the magic. When you enter the two numbers and click "Add" button, the Visual Studio Debugger pops up confirming the connection and a call being placed. I felt great when this happened, I had just called a method in a different application domain ( and in a different language ) from an entirely different application.
Hope this simple example helps you. Any comments are welcome.
Fun !!
Subscribe to:
Post Comments (Atom)
Thanks a lot!! got something useful done with with only a bit of trouble (the trouble I had was mostly with my config file and iis, not really as a result of this article). I'm using FlashDevelop instead of FlexBuilder(some minor differences to the article). I sorted out my IIS and config issues, and it's working great. Another thing I did, was that I accedentally named the service library by the default name, and then i did not update my flex app to match the namespace :P. if it might be useful, i can possibly share about these things later. do you have an article on RTMP and RTMPT too? since this is mostly what i would like to learn how to do with Fluorine. I'm going to search for that now. This will be great because the Fluorine docs are difficult for beginers as you pointed out. just right for people starting out, get's the important pieces in place so that one can learn from working code, and begin to use one's own methods and classes very quickly since it is easy to see what is going on. In any case, I can start to use FluorineFx for remoting... :D sweet! thanks again. daniel. another question: what version of FluorineFx are you using? i've got 1.0.0.13 (latest is 1.0.0.15 at the time of writing this)
ReplyDeleteHi Daniel,
ReplyDeleteI also have to use Fluorine for RTMP. Will post an article when I am done with it.
I used Fluorine 1.0.0.15 for the article
Hey, Did it work for you?
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletethanks! looking forward to that article. :D Haven't found anything in the way of a tutorial yet, mostly just trying to work from the docs, and with the config files, still can't seem to connect. I have setup a custom class to handle this (inherts from the AppHandling class, forget that exact name now EDIT:ApplicationAdapter), I still don't know how to register that app with it's handler. The status messages that I get each time I test: "Connection.Failed" on the IIS port number, or "Connection.Closed" when using the test server that comes with vwd2008 express. In the previous article,
ReplyDeleteHow do I configure this in easy steps? :D Kind Regards