Example name: ReturnType of DataTable's records
Description: Shows how to use WebORB's ReturnType attribute in server-side code to tell WebORB to serialize a DataTable's records as instances of a given client-side type.
Prerequisites:
Client-side code: Browse  Download
Server-side code: Browse  Download
Feature availability:
  • WebORB for .NET Development Mode
  • WebORB for .NET Community Edition
  • WebORB for .NET Enterprise Edition
Run example:
Key points:
  • WebORB serializes a DataTable as an Array (or ArrayCollection). By default, each record in that array is serialized as an ActionScript object, with the record's properties being serialized as dynamic name/value pairs.
  • It is often useful to serialize each record as an instance of given client-side class, instead of a dynamic object.
  • Using the ReturnType attribute tells WebORB to serialize a DataTable's records as instances of a given client-side type.
  • Server-side code:
    • Line 6: 'using Weborb.Service' declares the ReturnType attribute
    • Line 25: '[ReturnType("examples.weborb.Customer")]' tells WebORB to map all records in the following method's returned DataTable to instances of the client-side class, examples.weborb.Customer.
    • Line 45-57: Defines the returnsNull() method, which serves no purpose other than to tell WebORB that its code generator should generate a client-side Data Transfer Object class for this server-side class. The ReturnType attribute, above, refers to this WewbORB-generated Data Transfer Object class.
    • Line 61-75: Defines the server-side Customer class mentioned above.
  • Client-side code:
    • examples.weborb.vo.Customer.as: Defines the Data Transfer Object class generated by WebORB from the server-side Customer class, as described above.
    • main.mxml, lines 31-32: defines customersAC, an ArrayCollection, and binds its 'source' to the result of the remote service call to CustomerService.getCustomers().
    • main.mxml, line 41: binds the DataGrid's 'dataprovider' to 'customersAC', and hence to the result of the remote service call to CustomerService.getCustomers().
   
Things to try:
  • Instead of relying on WebORB's code generator to produce a client-side Customer class, (a) delete the definition of the Customer class and the returnNull() method from CustomerService.cs, and (b) define a Customer class on the client-side yourself. What are the advantages and disadvantages of each approach?
  • Delete the definition of the Customer class and the returnNull() method from CustomerService.cs, and also delete the 'ReturnType' attribute from getCustomers()'s definition. What corresponding changes are required in the client-side code? Why?
See also:
Screencast: [none]
Errata:
  • None yet known.