<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Florent Clairambault &#187; Flex</title>
	<atom:link href="http://florent.clairambault.fr/tag/flex/feed" rel="self" type="application/rss+xml" />
	<link>http://florent.clairambault.fr</link>
	<description></description>
	<lastBuildDate>Sat, 04 Feb 2012 19:56:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>.Net, Flex and WebORB.Net</title>
		<link>http://florent.clairambault.fr/net-flex-and-weborb-net?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=net-flex-and-weborb-net</link>
		<comments>http://florent.clairambault.fr/net-flex-and-weborb-net#comments</comments>
		<pubDate>Sat, 24 Oct 2009 07:47:41 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[M2M]]></category>
		<category><![CDATA[TC65]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[WebORB]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1825</guid>
		<description><![CDATA[I&#8217;ve been working on a project where we had to use Flex on a .Net environment and it had to be realtime. I was a little worried at first that it could be tricky to set up. But with WebORB.Net it&#8217;s pretty easy. We used the integrated RTMP (Real Time Messaging Protocol) messaging server. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a project where we had to use Flex on a .Net environment and it had to be realtime. I was a little worried at first that it could be tricky to set up. But with <a href="http://www.themidnightcoders.com/products/weborb-for-net/overview.html">WebORB.Net</a> it&#8217;s pretty easy. We used the integrated RTMP (Real Time Messaging Protocol) messaging server. It&#8217;s almost like using WCF. The most important differences are that, by default, objects are transmitted as Hashtable and calls can&#8217;t be synchronous. We can bind the object to right .Net object within the WebOrb management console but we decided to do it ourself using reflection (because we don&#8217;t like to depend too much on the management console).</p>
<p><strong>RTMP</strong><br />
The result is pretty impressive as it makes a really powerful real-time management system. And it&#8217;s freaking fast. Like WCF, it can handle concurrent calls. It&#8217;s in fact easier because everything is asynchronous but still, it does manage that. These calls are received on parallel threads.</p>
<p>The only problem with WebORB.Net is that you don&#8217;t have too much examples in the documentation. Our biggest problem was that we didn&#8217;t even knew how to detect what was the current calling connection on a method. This is pretty easy but you can&#8217;t exactly guess it. This is a dummy sample to show you how it&#8217;s done :</p>

<div class="wp_codebox"><table><tr id="p18252"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code" id="p1825code2"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> FlexConnectionsServer<span style="color: #008000;">:</span>ApplicationAdapter <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> _connectionIdCounter <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> Dictionary<span style="color: #008000;">&lt;</span>IConnection,<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> _connectionsToId <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Dictionary<span style="color: #008000;">&lt;</span>IConnection,<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// Returns the CURRENT connection (must be used from a method called by the flex client)</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> IConnection CurrentConnection <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> ConnectionHub<span style="color: #008000;">.</span><span style="color: #0000FF;">getConnectionLocal</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#125;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> CurrentID <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> _connectionsToId<span style="color: #008000;">&#91;</span> CurrentConnection <span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// When the RTMP service is loaded, we start the time dispatcher thread</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">bool</span> appStart<span style="color: #008000;">&#40;</span> IScope app <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Thread<span style="color: #008000;">&#40;</span> Thread_TimeDispatcher <span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// This method is called when a client connects</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">bool</span> appConnect<span style="color: #008000;">&#40;</span> IConnection conn, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> parms <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">lock</span> <span style="color: #008000;">&#40;</span> _connectionsToId <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			_connectionsToId<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> conn, _connectionIdCounter<span style="color: #008000;">++</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// This method is called when a client disconnects</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> appDisconnect<span style="color: #008000;">&#40;</span> IConnection conn <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">lock</span> <span style="color: #008000;">&#40;</span> _connectionsToId <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			_connectionsToId<span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span> conn <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// This is a sample method call</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">String</span> GetMyName<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;Client{0}&quot;</span>, CurrentId <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// This thread dispatches the current time to every client</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Thread_TimeDispatcher<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">while</span><span style="color: #008000;">&#40;</span> <span style="color: #0600FF; font-weight: bold;">true</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			var t <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">UtcNow</span><span style="color: #008000;">;</span>
			SendCommand<span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;CurrentTime&quot;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> t <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">1000</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// Call a remote method on each client connection</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> SendCommand<span style="color: #008000;">&#40;</span> <span style="color: #6666cc; font-weight: bold;">String</span> command, <span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">params</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">lock</span> <span style="color: #008000;">&#40;</span> _connectionsToId <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">foreach</span><span style="color: #008000;">&#40;</span> var kvp <span style="color: #0600FF; font-weight: bold;">in</span> _connectionsToId <span style="color: #008000;">&#41;</span>
				<span style="color: #008000;">&#40;</span> kvp<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #0600FF; font-weight: bold;">as</span> IServiceCapableConnection <span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span> command, <span style="color: #0600FF; font-weight: bold;">params</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>It&#8217;s a little bit like using WCF in Single instance mode.</p>
<p><strong>IIS 7.0 Setup</strong><br />
There was something really weird that happened with my IIS 7.0 on my Windows 7 x64. Using the RTMP connection, I frequently had null return values on .Net method calls. We firstly find a quick way to solve it : Recall each time we get a null value. It&#8217;s really dirty, but It worked as a very temporary solution.<br />
Then, when debugging on the IIS process, I noticed a lot of NullReferenceException exceptions displayed on the debugger console. They were about the WebORB &#8220;LicenseManager&#8221; class, and I had as much exceptions as I had null values on the Flex client. I tried a lot of things that didn&#8217;t do anything. And then, I changed the &#8220;Managemd pipeline mode&#8221; of the Application Pool from &#8220;Integrated&#8221; to &#8220;Classic&#8221;, and the problem was solved. The really weird stuff here is that <a href="http://www.themidnightcoders.com/products/weborb-for-net/developer-den/technical-articles/installing-weborb-on-vista-iis-7-install.html">WebORB recommends to use the &#8220;Integrated&#8221; mode</a>.</p>
<p><strong>MidnightCoders support</strong><br />
We asked MidnightCoders to send us a community edition license, and they instantly answered. We got our license within the 48 hours after our first mail (I was the one slowing it down).</p>
<p><strong>Quick note on the project</strong><br />
To give you a better view of the project I&#8217;m talking about :<br />
GPRS Equipment <--(<a href="http://florent.clairambault.fr/the-m2mp-protocol">M2MP protocol</a>)&#8211;> [Generic M2M Server] <--(WCF)--> [Business logic software] <--(WCF)--> [Flex connections server] <--(RTMP)--> Flex<br />
We&#8217;ve got a little equipment (<a href="http://florent.clairambault.fr/tag/tc65">TC65</a> based as you can guess) that connects to a generic server using our own (real-time and bandwidth optimized) protocol. A business logic software connects to this server using a WCF service. And then we have the WebORB.Net / IIS that connects to this business logic software. </p>
<p>WCF helps make very interesting .Net applications because it simplifies all the communication but can also create deadlocks you might not have seen. Take this example : You have a lock on the WCF Server on the clients list object, you make a call to the WCF client and this client makes a call to the WCF Server that also requires a lock. If you were doing all this client/server calls on the same process this wouldn&#8217;t be a problem. But as you use WCF client-to-server and server-to-client calls are made on differents threads. You create a deadlock (unless you set the OperationContract attribute to IsOneWay and/or you fix the deadlock source).</p>
<p>If you&#8217;re doing real-time applications, I would recommend to define all the frequently used methods with the &#8220;IsOneWay=true&#8221; option. </p>
<p><em>06/11/2009 Update : I added a sample server-to-client code because some people were interested by it.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/net-flex-and-weborb-net/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/15 queries in 0.006 seconds using disk: basic
Object Caching 374/396 objects using disk: basic

Served from: florent.clairambault.fr @ 2012-02-07 10:21:27 -->
