<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5364729821470345118</id><updated>2011-08-30T04:16:28.135-07:00</updated><category term='C#'/><category term='Cassini'/><category term='Web Server'/><category term='Cassini with HTTPS'/><category term='RTMP'/><category term='Fluorine'/><category term='Open source'/><category term='Flex 3.0'/><category term='C# web server'/><category term='Cassini with SSL'/><category term='RTM'/><category term='Messaging'/><category term='HTTPS'/><category term='Cassini 3.5'/><category term='Flex'/><category term='Secure Web Server.'/><category term='SSL'/><category term='Real Time Messaging'/><category term='Secure Cassini'/><category term='.NET'/><category term='FluorineFx'/><title type='text'>Flex  + C# + FluorineFx</title><subtitle type='html'>This was initially created to solve the problems faced while establishing connection between Flex and .NET using FluorineFx. Remoting and messaging and also deploying FluorineFx websites. However, now it will also list my works in C# and may be eventually some day to day tips and tricks on .NET, C#, Flex and Fluroine and also some open source projects.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://myprogrammingexperiences.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5364729821470345118/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://myprogrammingexperiences.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Gaurav</name><uri>http://www.blogger.com/profile/16538568567875701085</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5364729821470345118.post-6577047506008965319</id><published>2009-12-23T11:12:00.000-08:00</published><updated>2009-12-23T11:16:21.452-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cassini with SSL'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Secure Web Server.'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Web Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Cassini'/><category scheme='http://www.blogger.com/atom/ns#' term='C# web server'/><category scheme='http://www.blogger.com/atom/ns#' term='Cassini with HTTPS'/><category scheme='http://www.blogger.com/atom/ns#' term='SSL'/><category scheme='http://www.blogger.com/atom/ns#' term='Cassini 3.5'/><category scheme='http://www.blogger.com/atom/ns#' term='Secure Cassini'/><category scheme='http://www.blogger.com/atom/ns#' term='Open source'/><category scheme='http://www.blogger.com/atom/ns#' term='HTTPS'/><title type='text'>Secure Cassini</title><content type='html'>Everybody's heard of the open source web server by Microsoft, "Cassini". If not it is the same server that is used in Visual Studio (as far as i have read). You can find the full source code of cassini on the  &lt;a href="http://blogs.msdn.com/dmitryr/archive/2006/03/09/548131.aspx"&gt;msdn blog of Dmitryr&lt;/a&gt; .&lt;br /&gt;&lt;br /&gt;Now this server is a lacking in one functionality (which we required) and that is it does not support SSL or HTTPS connections. Hence, you cannot host a secure website on this server. &lt;br /&gt;This server is basically meant for local use and not to host websites that are accessible externally (use IIS instead). Although it can support external connections by changing just one parameter. Our requirement was to host a website locally on a computer which would be accessible by the host computer only (generally) but the connection that is established must be secure that is, it must use HTTPS.&lt;br /&gt;&lt;br /&gt;Configuring IIS has always been a tough job (at least for me), hence we came out with a solution and implemented HTTPS in Cassini, which can now host websites over secure connection using HTTPS.&lt;br /&gt;&lt;br /&gt;All you need to do is obtain a certificate (to prove your site's identity) this can be purchased (from VeriSign or other such service providers) or can be self signed. I will shortly upload the source files of the Secure version of Cassini and also the method to generate a self signed certificate.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5364729821470345118-6577047506008965319?l=myprogrammingexperiences.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myprogrammingexperiences.blogspot.com/feeds/6577047506008965319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://myprogrammingexperiences.blogspot.com/2009/12/secure-cassini.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5364729821470345118/posts/default/6577047506008965319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5364729821470345118/posts/default/6577047506008965319'/><link rel='alternate' type='text/html' href='http://myprogrammingexperiences.blogspot.com/2009/12/secure-cassini.html' title='Secure Cassini'/><author><name>Gaurav</name><uri>http://www.blogger.com/profile/16538568567875701085</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5364729821470345118.post-5773343047624881984</id><published>2009-10-08T06:31:00.000-07:00</published><updated>2011-08-18T01:48:19.384-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RTMP'/><category scheme='http://www.blogger.com/atom/ns#' term='Messaging'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Real Time Messaging'/><category scheme='http://www.blogger.com/atom/ns#' term='FluorineFx'/><category scheme='http://www.blogger.com/atom/ns#' term='RTM'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex'/><category scheme='http://www.blogger.com/atom/ns#' term='Fluorine'/><title type='text'>Real Time Messaging</title><content type='html'>Finally, after two days of hard work and lots of hick ups , I was able to implement real time messaging between C# and Flex.&lt;br /&gt;&lt;br /&gt;Let's get into code real fast as I know it must have been very frustrating trying to get it done (without any documentation from Fluorine or any help, I was unable to find it on google too, surprising).&lt;br /&gt;&lt;br /&gt;The example I show here is same as one of the samples provided by Fluorine however, I think if you are able to run this sample by your own code you can develop an application that is able to send messages as your requirements are. The example I used is of Date feed. We will send send date and time from the server side (C#) to the flex RTMP client and display it here.&lt;br /&gt;&lt;br /&gt;The C# code is as below. Create an empty solution add a Fluorine class library and a Fluorine Website to the solution. In the class library add a class "DateFeedService" as below.&lt;br /&gt;&lt;br /&gt;&lt;textarea rows="40" cols="70"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.Threading;&lt;br /&gt;&lt;br /&gt;using FluorineFx;&lt;br /&gt;using FluorineFx.Messaging;&lt;br /&gt;using FluorineFx.Messaging.Messages;&lt;br /&gt;&lt;br /&gt;namespace ServiceLibrary&lt;br /&gt;{&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Summary description for DateFeedService.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;[RemotingService]&lt;br /&gt;public class DateFeedService&lt;br /&gt;{&lt;br /&gt;private static Thread _thread;&lt;br /&gt;private static bool _isRunning = false;&lt;br /&gt;static object _objLock = new object();&lt;br /&gt;&lt;br /&gt;public DateFeedService()&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void toggle()&lt;br /&gt;{&lt;br /&gt;lock (_objLock)&lt;br /&gt;{&lt;br /&gt;if (!_isRunning)&lt;br /&gt;{&lt;br /&gt;_isRunning = true;&lt;br /&gt;_thread = new Thread(new ThreadStart(Push));&lt;br /&gt;_thread.Start();&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;_isRunning = false;&lt;br /&gt;_thread.Join();&lt;br /&gt;_thread = null;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void Push()&lt;br /&gt;{&lt;br /&gt;while (_isRunning)&lt;br /&gt;{&lt;br /&gt;MessageBroker msgBroker = MessageBroker.GetMessageBroker(null);&lt;br /&gt;DateTime now = DateTime.Now;&lt;br /&gt;AsyncMessage msg = new AsyncMessage();&lt;br /&gt;msg.destination = "datefeed";&lt;br /&gt;msg.clientId = Guid.NewGuid().ToString("D");&lt;br /&gt;msg.messageId = Guid.NewGuid().ToString("D");&lt;br /&gt;msg.timestamp = Environment.TickCount;&lt;br /&gt;Hashtable body = new Hashtable();&lt;br /&gt;body.Add("userId", "daemon");&lt;br /&gt;body.Add("msg", now.ToString());&lt;br /&gt;msg.body = body;&lt;br /&gt;msgBroker.RouteMessage(msg);&lt;br /&gt;Thread.Sleep(1000);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And the Flex side code is as below.&lt;br /&gt;&lt;br /&gt;&lt;textarea rows="40" cols="70"&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;br /&gt;&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" verticalScrollPolicy="off" horizontalScrollPolicy="off" creationComplete="initMessaging()"&gt;&lt;br /&gt;&lt;mx:Script&gt;&lt;br /&gt;&lt;![CDATA[   import mx.messaging.channels.StreamingAMFChannel;   import mx.messaging.channels.AMFChannel;   import com.MyCompany.MyProject.event.GetMessageEvent;   import mx.messaging.events.MessageEvent;   import mx.rpc.events.ResultEvent;      public function initMessaging():void   {    myConsumer.subscribe();   }     public function clickHandler():void   {    feeder.toggle();   }      public function messageHandler(event:MessageEvent):void    {            var body:Object = event.message.body;    lab1.text = body.userId + ": " + body.msg;   }      ]]&gt;&lt;br /&gt;&lt;/mx:Script&gt;&lt;br /&gt;&lt;br /&gt;&lt;mx:RemoteObject id="feeder" destination="fluorine"&gt;&lt;br /&gt;&lt;mx:method name="toggle"/&gt;    &lt;br /&gt;&lt;/mx:RemoteObject&gt;&lt;br /&gt;&lt;br /&gt;&lt;mx:Consumer id="myConsumer" destination="MyMessaging" message="messageHandler(event)"/&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;mx:Button label="Start" click="clickHandler()"/&gt;&lt;br /&gt;&lt;mx:Label id="lab1"/&gt;&lt;br /&gt;&lt;br /&gt;&lt;/mx:Application&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now comes the most important (and undocumented) part that will instruct the .NET side to start a RTMP server and listen on a particular port, this is the  configuration part.&lt;br /&gt;&lt;br /&gt;Since we are using Remoting and Messaging both in the same application we will have to configure both for the application to work.&lt;br /&gt;&lt;br /&gt;Moreover, configuration is required in the Flex and .NET side as well.&lt;br /&gt;&lt;br /&gt;The configuration for the flex side is as below:&lt;br /&gt;&lt;br /&gt;&lt;textarea rows="40" cols="70"&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;br /&gt;&lt;services-config&gt;&lt;br /&gt;&lt;services&gt;&lt;br /&gt;&lt;service id="remoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"&gt;&lt;br /&gt;&lt;destination id="fluorine"&gt;&lt;br /&gt;&lt;channels&gt;&lt;br /&gt;&lt;channel ref="my-amf"/&gt;&lt;br /&gt;&lt;/channels&gt;&lt;br /&gt;&lt;properties&gt;&lt;br /&gt;&lt;source&gt;ServiceLibrary.DateFeedService&lt;/source&gt;&lt;br /&gt;&lt;/properties&gt;&lt;br /&gt;&lt;/destination&gt;&lt;br /&gt;&lt;/service&gt;&lt;br /&gt;&lt;br /&gt;&lt;service id="message-service" class="flex.messaging.services.MessageService" messageTypes="flex.messaging.messages.AsyncMessage"&gt;&lt;br /&gt;&lt;adapters&gt;&lt;br /&gt;&lt;adapter-definition id="messagingAdapter" class="FluorineFx.Messaging.Services.Messaging.MessagingAdapter" default="true"/&gt;&lt;br /&gt;&lt;/adapters&gt;&lt;br /&gt;&lt;destination id="MyMessaging"&gt;&lt;br /&gt;&lt;adapter ref="messagingAdapter"/&gt;&lt;br /&gt;&lt;channels&gt;&lt;br /&gt;&lt;channel ref="my-rtmp"/&gt;&lt;br /&gt;&lt;/channels&gt;&lt;br /&gt;&lt;properties&gt;&lt;br /&gt;&lt;source&gt;*&lt;/source&gt;&lt;br /&gt;&lt;network&gt;&lt;br /&gt;&lt;!-- The session-timeout element specifies the idle time in minutes before a subscriber is unsubscribed. When you set the value to 0 (zero), subscribers are not forced to unsubscribe automatically. The default value is 20. --&gt;&lt;br /&gt;&lt;session-timeout&gt;20&lt;/session-timeout&gt;&lt;br /&gt;&lt;/network&gt;&lt;br /&gt;&lt;/properties&gt;&lt;br /&gt;&lt;/destination&gt;&lt;br /&gt;&lt;/service&gt;&lt;br /&gt;&lt;br /&gt;&lt;/services&gt;&lt;br /&gt;&lt;br /&gt;&lt;channels&gt;&lt;br /&gt;&lt;channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"&gt;&lt;br /&gt;&lt;endpoint uri="http://localhost:3262/MyWebsite/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/&gt;&lt;br /&gt;&lt;properties&gt;&lt;br /&gt;&lt;!-- &lt;legacy-collection&gt;true&lt;/legacy-collection&gt; --&gt;&lt;br /&gt;&lt;/properties&gt;&lt;br /&gt;&lt;/channel-definition&gt;&lt;br /&gt;&lt;br /&gt;&lt;channel-definition id="my-rtmp" class="mx.messaging.channels.RTMPChannel"&gt;&lt;br /&gt;&lt;endpoint uri="rtmp://{server.name}:2037" class="flex.messaging.endpoints.RTMPEndpoint"/&gt;&lt;br /&gt;&lt;!--         &lt;properties&gt;&lt;br /&gt;&lt;idle-timeout-minutes&gt;20&lt;/idle-timeout-minutes&gt;&lt;br /&gt;&lt;/properties&gt;&lt;br /&gt;--&gt;&lt;br /&gt;&lt;/channel-definition&gt; &lt;br /&gt;&lt;br /&gt;&lt;/channels&gt;&lt;br /&gt;&lt;/services-config&gt;&lt;br /&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Configuration for the C# side is as below. These files must be located in the Fluorine website we created earlier within the WEB-INF/flex folder.&lt;br /&gt;&lt;br /&gt;Three files are necessary.&lt;br /&gt;1. services-config.xml&lt;br /&gt;&lt;textarea rows="40" cols="70"&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;br /&gt;&lt;services-config&gt;&lt;br /&gt;&lt;services&gt;&lt;br /&gt;&lt;service-include file-path="remoting-config.xml" /&gt;&lt;br /&gt;&lt;service-include file-path="messaging-config.xml" /&gt;&lt;br /&gt;&lt;!-- &lt;service-include file-path="data-management-config.xml" /&gt; --&gt;&lt;br /&gt;&lt;/services&gt;&lt;br /&gt;&lt;br /&gt;&lt;security&gt;&lt;br /&gt;&lt;/security&gt;&lt;br /&gt;&lt;br /&gt;&lt;channels&gt;&lt;br /&gt;&lt;channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"&gt;&lt;br /&gt;&lt;endpoint uri="http://{server.name}:{server.port}/{context.root}/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/&gt;&lt;br /&gt;&lt;properties&gt;&lt;br /&gt;&lt;!-- &lt;legacy-collection&gt;true&lt;/legacy-collection&gt; --&gt;&lt;br /&gt;&lt;/properties&gt;&lt;br /&gt;&lt;/channel-definition&gt;&lt;br /&gt;&lt;br /&gt;&lt;channel-definition id="my-rtmp" class="mx.messaging.channels.RTMPChannel"&gt;&lt;br /&gt;&lt;endpoint uri="rtmp://{server.name}:2037" class="flex.messaging.endpoints.RTMPEndpoint"/&gt;&lt;br /&gt;&lt;properties&gt;&lt;br /&gt;&lt;idle-timeout-minutes&gt;20&lt;/idle-timeout-minutes&gt;&lt;br /&gt;&lt;/properties&gt;&lt;br /&gt;&lt;/channel-definition&gt;&lt;br /&gt;&lt;br /&gt;&lt;/channels&gt;&lt;br /&gt;&lt;/services-config&gt;&lt;br /&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;2. remoting-config.xml&lt;br /&gt;&lt;textarea rows="40" cols="70"&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;service id="remoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- DO NOT CHANGE &lt;adapters&gt; SECTION--&gt;&lt;br /&gt;&lt;adapters&gt;&lt;br /&gt;&lt;adapter-definition id="dotnet" class="FluorineFx.Remoting.RemotingAdapter" default="true"/&gt;&lt;br /&gt;&lt;/adapters&gt;&lt;br /&gt;&lt;br /&gt;&lt;default-channels&gt;&lt;br /&gt;&lt;channel ref="my-amf"/&gt;&lt;br /&gt;&lt;/default-channels&gt;&lt;br /&gt;&lt;br /&gt;&lt;destination id="fluorine"&gt;&lt;br /&gt;&lt;properties&gt;&lt;br /&gt;&lt;source&gt;*&lt;/source&gt;&lt;br /&gt;&lt;/properties&gt;&lt;br /&gt;&lt;/destination&gt;&lt;br /&gt;&lt;/service&gt;&lt;br /&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;3. messaging-config.xml&lt;br /&gt;&lt;textarea rows="40" cols="70"&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;service id="message-service" class="flex.messaging.services.MessageService" messageTypes="flex.messaging.messages.AsyncMessage"&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- DO NOT CHANGE &lt;adapters&gt; SECTION--&gt;&lt;br /&gt;&lt;adapters&gt;&lt;br /&gt;&lt;adapter-definition id="messagingAdapter" class="FluorineFx.Messaging.Services.Messaging.MessagingAdapter" default="true"/&gt;&lt;br /&gt;&lt;/adapters&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;destination id="MyMessaging"&gt;&lt;br /&gt;&lt;adapter ref="messagingAdapter"/&gt;&lt;br /&gt;&lt;properties&gt;&lt;br /&gt;&lt;network&gt;&lt;br /&gt;&lt;session-timeout&gt;0&lt;/session-timeout&gt;&lt;br /&gt;&lt;/network&gt;&lt;br /&gt;&lt;/properties&gt;&lt;br /&gt;&lt;channels&gt;&lt;br /&gt;&lt;channel ref="my-rtmp"/&gt;&lt;br /&gt;&lt;/channels&gt;&lt;br /&gt;&lt;/destination&gt;&lt;br /&gt;&lt;/service&gt;&lt;br /&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;The first configuration file sets up channels for Remoting and messaging and instructs to load the remaining two config files for the services section.&lt;br /&gt;The other two files deal with the configuration of the messaging and remoting adapters. The messaging config file configures the application to start RTMP server on a particular port and listen for incoming requests from subscribers.&lt;br /&gt;&lt;br /&gt;Hope the above example help you to send real time messages to your flex application from C#.&lt;br /&gt;Comments ?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5364729821470345118-5773343047624881984?l=myprogrammingexperiences.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myprogrammingexperiences.blogspot.com/feeds/5773343047624881984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://myprogrammingexperiences.blogspot.com/2009/10/real-time-messaging.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5364729821470345118/posts/default/5773343047624881984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5364729821470345118/posts/default/5773343047624881984'/><link rel='alternate' type='text/html' href='http://myprogrammingexperiences.blogspot.com/2009/10/real-time-messaging.html' title='Real Time Messaging'/><author><name>Gaurav</name><uri>http://www.blogger.com/profile/16538568567875701085</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5364729821470345118.post-1488522289245670318</id><published>2009-08-24T03:18:00.000-07:00</published><updated>2009-09-14T10:16:44.469-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex 3.0'/><category scheme='http://www.blogger.com/atom/ns#' term='FluorineFx'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex'/><category scheme='http://www.blogger.com/atom/ns#' term='Fluorine'/><title type='text'></title><content type='html'>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. &lt;br /&gt;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.&lt;br /&gt;Since Flex uses AMF and C# uses SOAP for remoting we need a gateway like FLuorinFx (or WebORB).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Requirements :&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;You will need the following softwares.&lt;br /&gt;1. Adobe Flex 3.0 (or above)&lt;br /&gt;2. MS Visual Studio 2005 (or above)&lt;br /&gt;3.FluorineFx (available at &lt;a href="http://www.fluorinefx.com/download.html"&gt;http://www.fluorinefx.com/download.html&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Create&amp;nbsp; 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.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;namespace MyDemoLib&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [RemotingService]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class Math&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Math()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public int add(int x,int y)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x + y;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;Now comes the Flex part.&lt;br /&gt;Create a simple project in flex.&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;The code is as below.&lt;br /&gt;&lt;br /&gt;&lt;textarea rows="40" cols="70"&gt;&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;br /&gt;&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"&gt;&lt;br /&gt;&lt;mx:Script&gt;&lt;br /&gt;&lt;![CDATA[  import mx.controls.Alert;  import mx.rpc.events.FaultEvent;  import mx.rpc.events.ResultEvent;    public function remoteAdd():void  {   myRemoteObj.add(int(txtNum1.text),int(txtNum2.text));   }  public function faultHandler(event:FaultEvent):void  {             Alert.show("Fault",  event.fault.toString());        }  public function resultHandler(event:ResultEvent):void  {   lblResult.text = "Result =" + int(event.result);  } ]]&gt;&lt;br /&gt;&lt;/mx:Script&gt;&lt;br /&gt;&lt;mx:RemoteObject id="myRemoteObj"      destination="fluorine"      source="MyDemoLib.MyMath"      fault="faultHandler(event)"&gt;&lt;br /&gt;&lt;mx:method name="add" result="resultHandler(event)"/&gt;&lt;br /&gt;&lt;/mx:RemoteObject&gt;&lt;br /&gt;&lt;mx:TextInput id="txtNum1"  x="89" y="76"/&gt;&lt;br /&gt;&lt;mx:TextInput id="txtNum2"  x="89" y="143"/&gt;&lt;br /&gt;&lt;mx:Button   x="109" y="210"  label="Add using Remoting"  click="remoteAdd()"/&gt;&lt;br /&gt;&lt;mx:Label   x="10" y="80"   text="Num 1"/&gt;&lt;br /&gt;&lt;mx:Label   x="10" y="147"   text="Num 2"/&gt;&lt;br /&gt;&lt;mx:Label x="47" y="272" width="179" height="26" fontSize="12" id="lblResult"/&gt;&lt;br /&gt;&lt;/mx:Application&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;In the above code we create a RemoteObject and use this object to call the remote method.&lt;br /&gt;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.&lt;br /&gt;You can do this by a right click on the flex project -&amp;gt; properties -&amp;gt;Flex compiler and include the path to this configuration file in the additional compiler arguments.&lt;br /&gt;"&lt;b&gt;-services "services-config.xml" &lt;/b&gt;"&lt;br /&gt;&lt;br /&gt;The configuration file is as below.&lt;br /&gt;&lt;br /&gt;&lt;textarea rows="25" cols="70"&gt;&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;br /&gt;&lt;services-config&gt;&lt;br /&gt;&lt;services&gt;&lt;br /&gt;&lt;service id="remoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"&gt;&lt;br /&gt;&lt;destination id="fluorine"&gt;&lt;br /&gt;&lt;channels&gt;&lt;br /&gt;&lt;channel ref="my-amf"/&gt;&lt;br /&gt;&lt;/channels&gt;&lt;br /&gt;&lt;properties&gt;&lt;br /&gt;&lt;source&gt;*&lt;/source&gt;&lt;br /&gt;&lt;/properties&gt;&lt;br /&gt;&lt;/destination&gt;&lt;br /&gt;&lt;/service&gt;&lt;br /&gt;&lt;/services&gt;&lt;br /&gt;&lt;br /&gt;&lt;channels&gt;&lt;br /&gt;&lt;channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"&gt;&lt;br /&gt;&lt;endpoint uri="http://localhost:1425/MyDemoWebsite/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/&gt;&lt;br /&gt;&lt;properties&gt;&lt;br /&gt;&lt;!-- &lt;legacy-collection&gt;true&lt;/legacy-collection&gt; --&gt;&lt;br /&gt;&lt;/properties&gt;&lt;br /&gt;&lt;/channel-definition&gt;&lt;br /&gt;&lt;/channels&gt;&lt;br /&gt;&lt;/services-config&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;All is done now you are ready to go.&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;Hope this simple example helps you. Any comments are welcome.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fun !! &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_XFQxqZBXLCM/Sq527Ge96II/AAAAAAAAAKE/ikFqcTZZUxs/s1600-h/Super.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_XFQxqZBXLCM/Sq527Ge96II/AAAAAAAAAKE/ikFqcTZZUxs/s400/Super.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5364729821470345118-1488522289245670318?l=myprogrammingexperiences.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://myprogrammingexperiences.blogspot.com/feeds/1488522289245670318/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://myprogrammingexperiences.blogspot.com/2009/08/though-i-am-new-to-flex-development-my.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5364729821470345118/posts/default/1488522289245670318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5364729821470345118/posts/default/1488522289245670318'/><link rel='alternate' type='text/html' href='http://myprogrammingexperiences.blogspot.com/2009/08/though-i-am-new-to-flex-development-my.html' title=''/><author><name>Gaurav</name><uri>http://www.blogger.com/profile/16538568567875701085</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_XFQxqZBXLCM/Sq527Ge96II/AAAAAAAAAKE/ikFqcTZZUxs/s72-c/Super.JPG' height='72' width='72'/><thr:total>5</thr:total></entry></feed>
