incubator-flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dahn Maier <>
Subject Re: flex and .net mvc4 webapi rest service
Date Wed, 21 Nov 2012 13:53:18 GMT
Use HTTPService and serialize / deserialize your as typed objects to / from

Here's a generic rest api call:

*// use a HTTPService - first configure it*

 *private* *function* configureService():*void* {

 service = *new* HTTPService();

// REST service path ie :"";

 service.url = Config.WEB_ROOT+*"/path/to/method"*;

 service.method = *"POST"*;

 service.useProxy = *false* ;

// set your response / fault event handlers

 service.addEventListener(ResultEvent.RESULT, onUrlSuccess) ;

 service.addEventListener(FaultEvent.FAULT, onUrlFault) ;


// call the service with the json object
public function callService(myObject:MyType):void{
    var myObjectJson:String = myObject.toJson();
    var data:Object = new Object();
// send the json as a post property
    data.json = myObjectJson;
    service.send( data);
// or send the json directly (depends on what your service expects

You also need to serialize your object as Json - I do it manually (very
simple entity) using the JSON class provided by Flex but you can also use
more sophisticated mechanisms if you have more complex objects (see
documentation on JSON or use as3corelib library)

Here is a class for sending image information back and forth with json
serialization / deserialization

 *public* *class* ImageInfo


 *public* *var* contentType:String ;

 *public* *var* fileName:String ;

 *public* *var* fileSize:int;

 *public* *var* imageRatio:Number;

 *public* *var* published:Boolean;

 *public* *var* sessionId:String;

 *public* *var* stringKey:String;

 *public* *var* title:String;

 *public* *var* uploadUrl:String;

 *public* *var* userKeyId:String;

 *public* *var* userName:String;

 *public* *var* searchTags:Array;


 * Constructor.


 *public* *function* ImageInfo(jsonResponse:Object = *null*) {

 *if*(jsonResponse != *null*)






 *public* *function* toJson():*{

 *// stringify the arrays separately*

   *var* searchTagsJson:Array = [];

 *if*(searchTags != *null* && searchTags.length > 0 ){

  *var* st:ArrayCollection = *new* ArrayCollection(searchTags);

  *for each* (*var* search:String *in* st){




   *var* json:Object = {














   *return* JSON.stringify(json);



 * Revives the object from a json object representation.


 *private* *function* fromJson(json:Object):*void*{

 *var* thisXML:XML = describeType(*this*);

 *for* ( *var* a:Object *in* thisXML.variable ){

  *var* propertyName:String = thisXML.variable.@name[a];


  *this*[*propertyName*] = json[propertyName];




On Wed, Nov 21, 2012 at 4:03 AM, Franca Daniel <> wrote:

> Hello,
> Any idea how to pass and receive objects to a webapi
> rest service (Json format) ?
> Thank you!

Dahn Maier
Maier Inc.

This transmission is intended solely for the person or organization to whom
it is addressed and it may contain privileged and confidential information.
If you are not the intended recipient you should not copy, distribute or
take any action in reliance on it. If you believe you received this
transmission in error please notify the sender.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message