.Net, Flex and WebORB.Net

I’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’s pretty easy. We used the integrated RTMP (Real Time Messaging Protocol) messaging server. It’s almost like using WCF. The most important differences are that, by default, objects are transmitted as Hashtable and calls can’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’t like to depend too much on the management console).

RTMP
The result is pretty impressive as it makes a really powerful real-time management system. And it’s freaking fast. Like WCF, it can handle concurrent calls. It’s in fact easier because everything is asynchronous but still, it does manage that. These calls are received on parallel threads.

The only problem with WebORB.Net is that you don’t have too much examples in the documentation. Our biggest problem was that we didn’t even knew how to detect what was the current calling connection on a method. This is pretty easy but you can’t exactly guess it. This is a dummy sample to show you how it’s done :

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
public class FlexConnectionsServer:ApplicationAdapter {
	private int _connectionIdCounter = 0;
	private Dictionary<IConnection,int> _connectionsToId = new Dictionary<IConnection,int>();
 
	// Returns the CURRENT connection (must be used from a method called by the flex client)
	private IConnection CurrentConnection { get { return ConnectionHub.getConnectionLocal(); } }
	private int CurrentID { get { return _connectionsToId[ CurrentConnection ]; } }
 
	// When the RTMP service is loaded, we start the time dispatcher thread
	public override bool appStart( IScope app ) {
		new Thread( Thread_TimeDispatcher ).Start();
	}
 
	// This method is called when a client connects
	public override bool appConnect( IConnection conn, object[] parms ) {
		lock ( _connectionsToId ) {
			_connectionsToId.Add( conn, _connectionIdCounter++ );
		}
 
		return true;
	}
 
	// This method is called when a client disconnects
	public override void appDisconnect( IConnection conn ) {
		lock ( _connectionsToId ) {
			_connectionsToId.Remove( conn );
		}
	}
 
	// This is a sample method call
	public String GetMyName() {
		return String.Format( "Client{0}", CurrentId );
	}
 
	// This thread dispatches the current time to every client
	private void Thread_TimeDispatcher() {
		while( true ) {
			var t = DateTime.UtcNow;
			SendCommand( "CurrentTime", new Object[] { t } );
			Thread.Sleep( 1000 );
		}
	}
 
	// Call a remote method on each client connection
	private void SendCommand( String command, Object[] params ) {
		lock ( _connectionsToId ) {
			foreach( var kvp in _connectionsToId )
				( kvp.Key as IServiceCapableConnection ).Invoke( command, params );
		}
	}
}

It’s a little bit like using WCF in Single instance mode.

IIS 7.0 Setup
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’s really dirty, but It worked as a very temporary solution.
Then, when debugging on the IIS process, I noticed a lot of NullReferenceException exceptions displayed on the debugger console. They were about the WebORB “LicenseManager” class, and I had as much exceptions as I had null values on the Flex client. I tried a lot of things that didn’t do anything. And then, I changed the “Managemd pipeline mode” of the Application Pool from “Integrated” to “Classic”, and the problem was solved. The really weird stuff here is that WebORB recommends to use the “Integrated” mode.

MidnightCoders support
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).

Quick note on the project
To give you a better view of the project I’m talking about :
GPRS Equipment <--(M2MP protocol)–> [Generic M2M Server] <--(WCF)--> [Business logic software] <--(WCF)--> [Flex connections server] <--(RTMP)--> Flex
We’ve got a little equipment (TC65 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.

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’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).

If you’re doing real-time applications, I would recommend to define all the frequently used methods with the “IsOneWay=true” option.

06/11/2009 Update : I added a sample server-to-client code because some people were interested by it.

16 thoughts on “.Net, Flex and WebORB.Net”

  1. Hey good article. Without WebOrb, how could you have bridged the gap between .NET and Flex client. And is possible without using IIS?

    1. Hi Michael,

      Thank you. We used the free and community version. I think you can only use WebOrb with IIS 5.0 or above. But with the professional version, you should be able to use it with a .Net desktop application.

  2. Thanks Florent,

    What about without using WebOrb? Management here, decided to say no to WebOrb, the professional license was too expensive. Have you explored RTMP services using FluorineFX? or some other method ?

  3. @Michael :
    Sorry for the very late reply. I haven’t checked FluorineFX. You might want to try the “community edition” which is the professional edition but limited to only one server.

    @lilii :
    WCF doesn’t work with flex out of the box.

    So, to answer your question “Why not ?”

    Because it doesn’t exist. We could have built a RTMP binding for WCF but that would have been a lot of work and we really didn’t have the time to accomplish it.

  4. here’s a challenge… If i want to develop an RTMP custom binding for WCF -is it possible? can you direct me to resources that wil guide me to it?
    I have experience with WCF but with RTMP-none…

  5. i have problem installing WebORB in windows 7

    i got a error like

    The installer was interupted before WebORB for .NET 3.6.0.3 could be installed. You need to restart the installer to try again.

    Click “Close” to exit.

    any quick fix will be helpful

  6. Yes I had the same problem below:

    The installer was interupted before WebORB for .NET 3.6.0.3 could be installed. You need to restart the installer to try again.

    It got resolved with the post above by configuring IIS6.0 compatibility mode.

  7. WebORB for .NET 4.0 (Beta) now supports AMF behavior for WCF services. This is by far one of our favorite new features. If you develop WCF services, you can use the WebORB’s AMF behavior to expose service via dedicated AMF-capable endpoint. Your services can be self-hosted or IIS-hosted. Documentation link: http://bit.ly/aTJkaF

    Also, if you would like to receive a free Community Edition license, you can request one here: http://bit.ly/agxnA1. We only recommend requesting a Community Edition license after you have had a chance to work with the WebORB product for awhile. You can download as many copies of WebORB running in development mode as you like. It is free for evaluation and development.

  8. Would you show the client side too? I’m having troubles invoking the “GetMyName” method. In the same solution I put the it in and calling it with a remoteobject but the ConnectionHub.getConnectionLocal() doesn’t return anything. They share the same data, I see the connection that was saved, but I have to indentify which client I should send the message to.

  9. Hi,
    Sorry I haven’t done the client side, I tried to read the flex code but really couldn’t find where to starts with the RTMP connection management.
    I’m not sure I understand everything about the ” ConnectionHub.getConnectionLocal()”. It should be used with an RTMP connection and within the server method called by the flex client.

    Sorry about the vague answers but I don’t remember much.

Leave a Reply

Your email address will not be published. Required fields are marked *