0

anybody knows if it is possible to do calls from flash to asp.net mvc actions using amf remoting ?

if yes, how? which technologies should be used and how to combine them

on the flash side it would be something like this:

    //Connect the NetConnection object
    var netConnection: NetConnection = new NetConnection();
    netConnection.connect("http://localhost:59147/Home/Index");

   //Invoke a call
   log("invoke call TestMethod");
   var responder : Responder = new Responder( handleRemoteCallResult, handleRemoteCallFault);
   netConnection.call('TestMethod', responder, "Test");

I tried this and it hits the action but I can't find the 'TestMethod' and "Test" anyware in the Request

Thank You

Omu
  • 69,856
  • 92
  • 277
  • 407
  • did you try to use .NET client AMF libraries, there is a list on http://en.wikipedia.org/wiki/Action_Message_Format#Support_for_AMF – Antonio Bakula May 11 '12 at 17:05
  • @AntonioBakula I tried FluorineFx but it works with RemoteObjects only, I can't change the flash side and it uses NetConnection the way I showed above – Omu May 11 '12 at 19:17

1 Answers1

2

I don't have a complete answer, but this could help you in the start.

You could use FluorineFx, that is a good start as it implements all the AMF stuff and it has AMFWriter/Reader, AMFDeserializer and so, play with them.

using System.Web.Mvc;
using FluorineFx.IO;

public class AMFFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        if (filterContext.HttpContext.Request.ContentType == "application/x-amf")
        {
            var stream = filterContext.HttpContext.Request.InputStream;

            var deserializer = new AMFDeserializer(stream);
            var message = deserializer.ReadAMFMessage();

            foreach (var body in message.Bodies) // not foreach, just the first one
            {
                filterContext.ActionParameters["method"] = body.Target;
                filterContext.ActionParameters["args"] = body.Content;
            }

            base.OnActionExecuting(filterContext);
        }
    }
}

[AMFFilter]
[HttpPost]
public ActionResult Index(string method, object[] args)
{
    return View();
}

This is just the first part. Returning binary data and stuff could be handled by some kind of custom ActionResult, but that one you know how to do from here AMF ActionResult for asp.net mvc ?

Good luck.

Community
  • 1
  • 1
mizi_sk
  • 1,007
  • 7
  • 33
  • Thank you, it works, except when I send an object I get a dictionary at the c# side, do you know if it's possible to make deserialize into an object ? – Omu May 14 '12 at 11:08
  • 1
    ok, found this one, I used this: http://www.fluorinefx.com/docs/fluorine/classmappingas3.html and now it maps the as object to .net – Omu May 14 '12 at 11:36
  • @ChuckNorris class mapping and aliases, yes! and you can save some traffic when using custom serialization via IExternalizable (however not your case when you can't change client side) – mizi_sk May 14 '12 at 15:03