Blog to discuss Midnight Coders products features, ideas and trends in development of Rich Internet Applications

Wednesday, October 31, 2007

Flex remoting code generator improvements

In my previous post I described the improvements in integration between .NET collections and ActionScript ArrayCollection class. This post describes the changes in the ActionScript3 remoting code generator in the upcoming 3.4 release of WebORB for .NET.

Concept
The idea is very simple, the management console for WebORB includes a service browser where you can see all the deployed assemblies. You can explore an assembly and see all the classes contained within. Upon selecting a class, WebORB generates ActionScript code you could use to invoke the selected class.

Code Structure
The new code structure is simple and can fit into many applications without any changes. The generated code consists of a controller (service) class, a bindable model class which aggregates the responses and optionally value object classes (they will be present if the remote class accepts or returns any complex types. The diagram below describes the code structure and how it would fit into a Flex application:

The two boxes in the middle represent the Service (FooService) and Model (FooModel) classes for a Foo class deployed on the server-side. The service class has the same methods as the remote counterpart. The View, which is an MXML application or component uses the service class to issue remote method invocations. All the RemoteObject code is encapsulated inside of the service class. When the service gets a response from the server, it updates the model object. The view can use Flex data binding to the model object and is automatically updated when the model changes.

Trying it out
Curious what the actual code looks like and care to try it out? Well, you're a download away (maybe two). Make sure to download and install the latest version of the product (3.3), then go to the WebORB nightly builds section in the interest group and download the file from 10-31-07 or later. The zip you download contains 3 files:
  • weborb.dll - must go into the /bin folder of the product installation
  • weborb.config - goes into the root folder of your weborb-enabled virtual directory
  • flex-remoting-as3.xslt - goes into [WEBORB-PATH]\weborbassets\codegen
If you experience any problems with the product or the feature, post to the WebORB interest group.

Tuesday, October 30, 2007

Flex and WebORB for .NET in action

Check out this Flex application powered by WebORB for .NET developed by Esria.

Use the following credentials to login:
userid: 1234567
password: 1234

The application utilizes and demonstrates the following features:
  • Flex charting
  • Flex Remoting (RemoteObject API)
  • Cairngorm framework
  • Authentication via custom WebORB handler

Monday, October 29, 2007

.NET collections and ArrayCollection (WebORB 3.4)

Starting this week I plan to introduce the new features from the upcoming 3.4 release of WebORB for .NET. The first one is support for ActionScript ArrayCollections. The product offers several options:
  1. Serializing ICollection instances as ArrayCollection:

    WebORB can be configured to serialize all instances of System.Collections.ICollection as ArrayCollection. The configuration setting can be found in weborb.config. Set the value to 'no' to enable serialization of ICollection instances as ArrayCollection:
    <legacyCollectionSerialization>no</legacyCollectionSerialization>

  2. Serializing specific collections as ArrayCollection:

    It may be important to map only certain collections to be serialized as ArrayCollection. In that case, set the configuration setting shown above to 'yes' and tag your collections with the following interface:
    Weborb.Types.IWebORBArrayCollection


    The interface does not declare any methods and is recognized by WebORB as a marker interface forcing collection serialization as ArrayCollection.

  3. Using built-in WebORB collections:

    WebORB includes two collection classes serialized as ArrayCollection objects. One of the classes is a standard IList implementation and the other is a generic version:
    Weborb.Types.WebORBArrayCollection : ArrayList

    Weborb.Types.Generic.WebORBArrayCollection<T> : List<T>


  4. Using custom serializer to serialize specific collection classes as ArrayCollection:

    If none of the options listed above work out, you can use a custom serializer to serialize your collection class as ArrayCollection. This is usually the case when you use a code generator or a class library where modifications to the created/provided classes are not possible. Create a serializer class as shown below:
    using System.Collections;
    using Weborb.Writer;

    public class CustomCollectionWriter : ArrayWriter
    {
    public override void write( object obj, IProtocolFormatter writer )
    {
    ArrayList array = new ArrayList( (ICollection) obj );

    writer.BeginWriteNamedObject( "flex.messaging.io.ArrayCollection", 1 );
    writer.WriteFieldName( "source" );
    writer.BeginWriteFieldValue();

    base.write( array.ToArray(), writer );

    writer.EndWriteFieldValue();
    writer.EndWriteNamedObject();
    }
    }


    Register the serializer either in weborb.config or using the API as shown below:

    weborb.config: add the following XML element into the customWriters block. Make sure to modify the namespaces of the custom collection and the serializer types:
    <customWriter>
    <className>com.acme.CustomCollectionType</className>
    <writerClassName>CustomCollectionWriter </writerClassName>
    </customWriter>


    Registering serializer using API: serializer can be registered in the Application_Start event handler in Global.asax:
    Type collectionType = typeof( CustomCollectionType );
    Weborb.Writer.MessageWriter.AddTypeWriter( collectionType, new CustomCollectionWriter() );


  5. Sending ArrayCollection instances to .NET:

    WebORB 3.4 includes configuration settings to support sending ArrayCollection objects to .NET. WebORB can map ArrayCollection to any linear collection type, so the method argument can be any subclass of ICollection.
Until the new version is released, you can download an intermediate build from the Files section of the WebORB interest group (use the latest build there). If you do not have the product installed, make sure to download WebORB distribution from the website first, then upgrade to the latest build.