3

Is it possible to return a serialized AMF object in a control action in ASP.net MVC?

Has anyone tried this before?

vvvvv
32.9k19 gold badges70 silver badges103 bronze badges
asked Apr 2, 2009 at 14:54
1
  • Can you provide a little more information as to what you're looking to do? I'm assuming you have some kind of Flash / Flex widget in your UI and want to provide data to it..? Commented Apr 4, 2009 at 20:43

3 Answers 3

1

I have little to no experience with MVC but I have done some testing with writing AMF data to a Flash client. What I did was to build a Generic Handler which used ByteArray class in FluorineFX. I created an object instance and wrote it to the ByteArray with WriteObject(). I then wrote the data of the ByteArray to the Response Stream. In Flash I then used a standard URLLoader and used ReadObject() from the (URLLoader.data as ByteArray) and I had my object deserialized and ready to go. (Of course I had to do all the RemoteClass and registerClassAlias muck first)

My guess is that the MVC Action lets you access the Response Stream as well so you should be set.

answered May 4, 2009 at 11:41
Sign up to request clarification or add additional context in comments.

Comments

1

I have no idea what an AMF object is (yes, i can google it but i won't). BUT, u can serialize any object in ASP.MVC. For example, returning an JSON object is an example of using the built in serialization.

check this previous SO question out:

public ActionResult MyAction()
{ 
 ... 
 // Populate myObject 
 return new JsonResult{ Data = myObject };
}

So the trick here, is that you need to make sure all the objects inside one of these AMF object can be serialised. If not, then don't forget you can return a serialised anonymous object.

eg.

public ActionResult MyAction()
{ 
 ... 
 // Populate myObject 
 return new JsonResult
 { 
 Data = new
 {
 Id = object.Id,
 Name = object.FirstName + ' ' object.Surname,
 .... etc ....
 }
 };
}

hth.

answered May 4, 2009 at 12:02

Comments

1

You can also create your own ActionResult classes, if the existing ones don't allow you to emit the format that you need.

This site has information on creating custom ActionResults: http://blogs.msdn.com/jowardel/archive/2009/03/11/asp-net-rss-actionresult.aspx

answered May 12, 2009 at 17:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.