RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Connecting a Smartphone 2003 Application to a Remoting Infrastructure : Page 2

Despite the fact that remoting is not currently supported in .NET Compact Framework applications running on the Smartphone 2003 platform, by using a third-party object request broker (ORB) you can interact with remote objects.

The Subscriber Project
In the .NET Compact Framework, only the main thread of an application is allowed to access UI controls directly. Because of this restriction, the host cannot simply invoke the method displayMessage() to write to the subscriber's display (the ORB is multithreaded and displayMessage() runs as a separate thread). The main dialog's interface AsyncUIAccess provides a workaround. The implementation of the method writeLog() writes to a queue. A timer empties the queue on a regular basis and writes all content to the display. This interface is defined in MainDialog.cs. FrmChatSubscriber implements the writelog() method:

   public interface AsyncUIAccess
      void writeLog(string a_strMsg); 
The rest of the presentation code should be straightforward to read and understand (see Listing 1). The remainder of the article will walk you through the class implementations, the subscriber interface, and the Connection class that provides a wrapper for the remote objects and manages the connection.

Figure 3. The Subscriber Project: The subscriber project contains the folders that help to organize the code.
The folder /Serializables contains the implementations of the CORBA valuetypes. One of these is SubscriberAccountImpl (see Listing 2). While the class methods are trivial, the class declaration is not. The class is derived from the abstract class SubscriberAccount which was generated and is declared in Chat.cs. The suffix "Impl" is a naming convention that serves as a reminder that this is an implementation of an abstract class. The generated parent SubscriberAccount is derived from Middsol.CORBA.portable.StreamableValue—the MiddCor representation of the CORBA valuetype. The same applies to the class SubscriberInfoImpl in Listing 3.

The subscriber interface in SubscriberImpl.cs exposes one method, displayMessage(), that the host can call:

   namespace DotNetClient
      public class SubscriberImpl: 
         private  AsyncUIAccess 
         public SubscriberImpl(
            AsyncUIAccess a_oUserInterface)
            m_oUserInterface = a_oUserInterface;
         public override void displayMessage(
            string a_strName, string a_strMsg)
               "<" + a_strName + "> '" + 
               a_strMsg + "'");
SubscriberImpl extends SubscriberPOA (POA stands for Portable Object Adapter) which is also a generated class. When a client invokes a server object, the POA helps the request broker activate the appropriate object and deliver requests to it.

The last module deserving of attention on the client side is Connection.cs (see Listing 4). This class contains the methods that manage the communication between subscriber and host. It maintains a reference to the host and to its own interface. It also creates an object request broker instance (ORB). It implements the methods shown in Table 1:

Table 1. Connection Class Methods: The connection class contains the methods that manage communications between the subscriber and the host.
Method Description
signOn() A public method called by the user interface when the subscriber wants to connect to a host.
signOff() A public method that calls the same method on the host to remove the calling instance from the list of subscribers.
sendMessage() A public method that makes a remote call to the same method on the host.
initialize() Initializes the ORB.
initCORBA() This method contains standard CORBA initialization code. It uses the .NET DNS API to get the local device's IP address, instantiates a new ORB, retrieves a reference to the newly created root portable object adapter (POA), and "narrows" it to the correct type (Middsol.PortableServer.POA). Finally, it activates the POA that has been in a holding state.
deinitCORBA() Destroys the ORB.
connectToHost() Uses the MiddSol Name Service to locate the host. It requires an IP address, connects to the name server on this host and requests the location of a server called "ChatHost". By default, the Name Service process listens on port 2809.
displayListOfSubscribers() Iterates through the list of subscribers that the host returned and writes each entry to the list box on the screen.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date