Example name: Mapping client and server-side objects between Flex and .NET
Description: The example demonstrates the following:
  • Usage of the flash.net.registerClassAlias API as well as the RemoteObject class attribute. Both approaches establish a mapping between server- and client-side value object
  • Server-side class uses Application scope, so only one instance of the class will be created for all connected clients
Client-side code: Browse  Download
Server-side code: Browse  Download
Product edition availability:
  • WebORB Standard Edition (localhost clients only)
  • WebORB Professional Edition
  • WebORB Enterprise Edition
Run example:
Key points:
  • The mapping between client and server class takes place in the init() method registered as the applications creationComplete handler:
    flash.net.registerClassAlias( "Weborb.Examples.PhoneBookRecord", PhoneBookEntryVO );
     
  • Client class PhoneBookEntryVO corresponds to the server class Weborb.Examples.PhoneBookRecord. The classes are shown below:
     
    Client class Server class
    package PhoneBook
    {
      [RemoteClass(alias="Weborb.Examples.PhoneBookRecord")]
      public class PhoneBookEntryVO
      {
        public var firstName:String;
        public var lastName:String;
        public var phoneNumber:String;
      }
    }
    namespace Weborb.Examples
    {
      public class PhoneBookRecord
      {
      private string _firstName;
      private string _lastName;
      private string _phoneNumber;

      public string firstName
      {
        get { return _firstName; }
        set { _firstName = value; }
      }

      public string lastName
      {
        get { return _lastName; }
        set { _lastName = value; }
      }

      public string phoneNumber
      {
        get { return _phoneNumber; }
        set { _phoneNumber = value; }
      }
    }

  • Notice how client class fields correspond to the server class property names
  • Notice the [RemoteObject] attribute in the client class definition. The attribute maps the class to the remote counter part. The attribute is commented out in the example's source, since an alternative approach is used.
  • .NET service for the example uses Application scope defined via the ApplicationActivation attribute:
     
    namespace Weborb.Examples
    {
      [ApplicationActivation()]
      public class PhoneBook
      {
        private List<PhoneBookRecord> records = new List<PhoneBookRecord>();

        public PhoneBookRecord addEntry( PhoneBookRecord record )
        {
          records.Add( record );
          return record;
        }

        public List<PhoneBookRecord> getEntries()
        {
          return records;
        }
      }
    }
Things to try:
  • Add an entry that starts with a number or any symbol that does not have a matching tab