Both JavaScript and ActionScript environments support a limited number of data types. For example, there is only one type representing a number, regardless whether the number is a short, an integer or a float. Complex types can be described as associative arrays, anonymous objects or specific instances of JS or AS classes. Since .NET is a strongly-typed environment, the arguments passed into the method on the client side must be adapted to the formal argument types of the server-side method. Consider the following example:
The code below returns the size of the array passed as the argument:
| C# method |
| public
int getArraySize( ArrayList arrayObject ) { return arrayObject.Count; } |
To invoke the method above from a rich client, the following code may be used:
| Flash Client | AJAX Client | |
| //
create an instance of array var arrayObject = new Array(); arrayObject[ 0 ] = "new york"; arrayObject[ 1 ] = "paris"; arrayObject[ 2 ] = "london"; var cnxn = NetServices.createGatewayConnection( "http://host:port/weborb.aspx" ); var remoteService = cnxn.getService( "ArraySizeService" ); remoteService.getArraySize( arrayObject ); // process method invocation response function getArraySize_Result( result ) { trace( "array size is " + result ); } |
var
webORBURL = "http://host:port/weborb.aspx" ); var remoteService = webORB.bind( "ArraySizeService", webORBURL ); var arrayObj = Array( "new york", "paris", "london" ); var arraySize = remoteService.getArraySize( arrayObj ); alert( "array size is " + arraySize ); |
In the example above, client code creates an instance of an ActionScript or
JavaScript array, while the server-side method accepts Vector or ArrayList as
an argument. WebORB automatically converts data received from clients to the
types expected by the invoked method. The process of data type conversion is
called type adaptation. WebORB's type adaptation capabilities supports
conversion of all primitive types, collections, complex types and arrays. The same data type received from a client can be adapted
to multiple data types from the backend object depending on the method's formal
argument types. For example, if the server-side method above is to be rewritten
as below, WebORB would automatically handle the change.
| C# method |
| public
int getArraySize( string[] arrayObject ) { return arrayObject.Length; } |
Below is a summary of all supported type adaptation mappings. Items in the Client Type column are the data types created in the client's ActionScript or JavaScript. Items in the .NET type columns are the data types to which the corresponding client arguments can be automatically converted. For example, if a client sends a String as an argument to a method, the corresponding .NET method argument can be any of the following types: string, System.Text.StringBuilder, char[], byte[], char, Boolean.
For more information about type adaptation and argument serialization, refer to the links below: