Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The trick is to use <code>FluorineFx.IO.AMFMessage</code> with AMFBody as a result object and set a <code>Content</code> property.</p> <p>You can see this in Charles proxy with other working examples (I've used great <a href="http://www.themidnightcoders.com/examples" rel="nofollow">WebORB examples</a>, specifically <a href="http://www.themidnightcoders.com/examples?eid=1305140498614" rel="nofollow">Flash remoting Basic Invocation AS3</a>)</p> <p>I've updated AMFFilter to support <code>Response</code> parameter that AMFBody needs. Maybe it could be solved more elegantly by some current context cache, don't know.</p> <p>Code follows:</p> <pre><code>public class AmfResult : ActionResult { private readonly object _o; private readonly string _response; public AmfResult(string response, object o) { _response = response; _o = o; } public override void ExecuteResult(ControllerContext context) { context.HttpContext.Response.ContentType = "application/x-amf"; var serializer = new AMFSerializer(context.HttpContext.Response.OutputStream); var amfMessage = new AMFMessage(); var amfBody = new AMFBody(); amfBody.Target = _response + "/onResult"; amfBody.Content = _o; amfBody.Response = ""; amfMessage.AddBody(amfBody); serializer.WriteMessage(amfMessage); } } </code></pre> <p>For this to work, you need to decorate method on the controller with AMFFilter</p> <pre><code>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(); var body = message.Bodies.First(); filterContext.ActionParameters["target"] = body.Target; filterContext.ActionParameters["args"] = body.Content; filterContext.ActionParameters["response"] = body.Response; base.OnActionExecuting(filterContext); } } } </code></pre> <p>which would look something like this</p> <pre><code>[AMFFilter] [HttpPost] public ActionResult Index(string target, string response, object[] args) { // assume target == "TestMethod" and args[0] is a String var message = Convert.ToString(args[0]); return new AmfResult(response, "Echo " + message); } </code></pre> <p>Client side code for reference</p> <pre><code>//Connect the NetConnection object var netConnection: NetConnection = new NetConnection(); netConnection.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); netConnection.connect("http://localhost:27165/Home/Index"); //Invoke a call var responder : Responder = new Responder( handleRemoteCallResult, handleRemoteCallFault); netConnection.call('TestMethod', responder, "Test"); private function onNetStatus(event:NetStatusEvent):void { log(ObjectUtil.toString(event.info)); } private function handleRemoteCallFault(...args):void { log(ObjectUtil.toString(args)); } private function handleRemoteCallResult(message:String):void { log(message); } private static function log(s:String):void { trace(s); } </code></pre> <p>If you would like to return fault, just change this line in AMFResult</p> <pre><code>amfBody.Target = _response + "/onFault"; </code></pre> <p><em>I like ObjectUtil.toString() formatting, but just remove it if you don't have Flex linked.</em></p> <p><em>BTW, do you really need this in ASP.NET MVC? Maybe simple ASHX handler would suffice and performance would be better, I don't know. The MVC architecture is a plus I presume.</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload