Getting Started

Server Setup
Action Script 2.0 Sample
Action Script 3.0 Sample
Client Setup

Examples

All of the examples are checked into source code - download the trunk, open the Solution with Visual Studio 2008, and you will find the Examples already loaded.
Note: Flash Remoting will not allow you to access a specific port, so you will either need to configure the development server to run on port 80 or configure the examples to run under IIS.

Example 1 - Hello World

In this example, we explore a basic OperationContract with only a return string.
[OperationContract]
string HelloWorld(); 

Example 2 - Simple Parameters

In this example, we take a look at very simple input parameters in this Calculator service. We also note that AMF uses the 'double' data type for all serialization, so floats and decimals may have rounding errors.
[OperationContract]
int Add(int a, int b);

[OperationContract]
float AddFloat(float a, float b);

Example 3 - Data Contract

We begin to get more complex with example 3 by exploring complex data types declared using DataContracts.
[OperationContract]
StockData GetItemData(ItemDescription item);


DataContract
public class StockData
{
[DataMember]
public int Quantity { get; set; }
DataMember
public double Price { get; set; }
DataMember
public string Name { get; set; }
}

DataContract
public class ItemDescription
{
[DataMember]
public int ItemId { get; set; }
DataMember
public string Name { get; set; }
}
}}

Example 4 - Message Contract

We explore message contracts and how they extend to Action Script with this next example while revisiting our Calculator service.
[OperationContract]
MathResult Add(MathParameters parameters);

[MessageContract]
public class MathParameters
{
    [MessageBodyMember]
    public double a { get; set; }
    [MessageBodyMember]
    public double b { get; set; }
}

[MessageContract]
public class MathResult
{
    [MessageBodyMember]
    public double Result { get; set; }
}

Example 5 - Headers

Message headers are important logical considerations for some services; in this example, we explore how they operate in Action Script.
[OperationContract]
MathResult Add(MathParameters parameters);

[MessageContract]
public class MathParameters
{
    [MessageHeader]
    public AuthenticationHeader Authentication { get; set; }
    [MessageBodyMember]
    public double a { get; set; }
    [MessageBodyMember]
    public double b { get; set; }
}

[DataContract]
public class AuthenticationHeader
{
    [DataMember]
    public string User { get; set; }
}

[MessageContract]
public class MathResult
{
    [MessageBodyMember]
    public double Result { get; set; }
    [MessageBodyMember]
    public string User { get; set; }
}

Example 6 - Faults

In this final example, we take a look at message faults.
[OperationContract]
[FaultContract(typeof(NotAuthorizedFault))]
MathResult Add(MathParameters parameters);

[MessageContract]
public class MathParameters
{
    [MessageHeader]
    public AuthenticationHeader Authentication { get; set; }
    [MessageBodyMember]
    public double a { get; set; }
    [MessageBodyMember]
    public double b { get; set; }
}

[DataContract]
public class AuthenticationHeader
{
    [DataMember]
    public string User { get; set; }
}

[DataContract]
public class NotAuthorizedFault
{

}

[MessageContract]
public class MathResult
{
    [MessageBodyMember]
    public double Result { get; set; }
}

Example 7 - Known Types

There comes a point in almost every interface where you find that you need extensibility. WCF supports KnownTypes for that reason; this example shows how they get translated through AMF. In ActionScript 2, the amfType property gets added to the object to indicate which subtype to use, or left off to use the base type.
[OperationContract]
string AddPerson(Person person);

[DataContract]
[KnownType(typeof(Contract.Teacher))]
public class Person
{
    [DataMember]
    public string FirstName { get; set; }
    [DataMember]
    public string LastName { get; set; }
}

[DataContract]
public class Student : Person
{
    [DataMember]
    public string Major { get; set; }

    public override string ToString()
    {
        return FirstName + " " + LastName + ", " + Major + " major";
    }
}

[DataContract]
public class Teacher : Person
{
    [DataMember]
    public string Department { get; set; }

    public override string ToString()
    {
        return FirstName + " " + LastName + ", teacher of " + Department;
    }
}

Last edited Oct 21, 2009 at 9:18 PM by mdekrey, version 7

Comments

No comments yet.