Search code examples
.netasp.net-mvcactionscript-3flashamf

use amf remoting with asp.net mvc


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


Solution

  • 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.