The following sections describe how to work with the built-in data types.
By default, developers get a lot of classes/types from both Flex SDK and the .NET class library. This includes primitive types, strings, dates, collections, and arrays. WebORB uses loose type marshalling rules. As a result, objects and values sent from ActionScript can be adapted to the types required by server-side methods. To understand the benefits of type adaptation, consider the following C# code snippet:
using System;
namespace GettingStarted.Examples
{
public class EchoService
{
public int echoInteger( int intValue )
{
return intValue;
}
}
}
And compare it to the following VB.NET code:
Imports System Namespace GettingStarted.Examples Public Class EchoService Public Function echoInteger(ByVal intValue As Integer) As Integer Return intValue End Function End Class End Namespace
The echoInteger method
accepts and returns an integer value. Due to type adaptation, the client code
can use any of the following argument types: int, uint, Number, and String.
See the following ActionScript example:
public function invokeEchoService():void
{
// construct remote object proxy
var echoIntService:RemoteObject = new RemoteObject( "GenericDestination" );
// attach 'result' and 'fault' listeners
echoIntService.echoInteger.addEventListener( ResultEvent.RESULT, gotResult );
echoIntService.echoInteger.addEventListener( FaultEvent.FAULT, gotFault );
var intValue:int = 21;
var uintValue:uint = 21;
var numberValue = new Number( 21 );
echoIntService.echoInteger( intValue );
echoIntService.echoInteger( uintValue );
echoIntService.echoInteger( numberValue );
// the string argument is parsed as integer
echoIntService.echoInteger( "21" );
}
public function gotResult( evt:ResultEvent ):void
{
Alert.show( "got result " + evt.result );
}
public function gotFault( evt:FaultEvent ):void
{
Alert.show( "got fault " + evt.fault.faultString );
}
The C# and VB.NET code in the example above uses the integer data type. However, for the
same ActionScript code, the argument type in the server code can be other
numeric and non-numeric types. Table 1 summarizes the type mappings
from ActionScript to .NET.
| Sent ActionScript type | .NET argument type | Comments |
|---|---|---|
|
If the .NET type is nullable (for example, |
|
|
||
|
Incoming value is treated as milliseconds. The |
|
|
|
|
|
Uses the |
|
|
|
|
|
Incoming string value is converted to a byte array using the UTF8 encoding. |
|
|
Uses the first character from the incoming string value. |
|
|
Uses |
|
|
If the server-side argument is an instance of |
|
|
Creates an instance of |
|
|
|
|
|
Uses |