【问题标题】:use amf remoting with asp.net mvc通过 asp.net mvc 使用 amf 远程处理
【发布时间】:2012-05-09 15:52:41
【问题描述】:

有人知道是否可以使用 amf 远程处理从 flash 调用 asp.net mvc 操作?

如果是,如何?应该使用哪些技术以及如何将它们结合起来

在闪存方面,它会是这样的:

    //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");

我试过了,它触发了操作,但我在请求中找不到任何“TestMethod”和“Test”

谢谢

【问题讨论】:

  • 您是否尝试使用.NET 客户端 AMF 库,en.wikipedia.org/wiki/Action_Message_Format#Support_for_AMF 上有一个列表
  • @AntonioBakula 我尝试了 FluorineFx,但它仅适用于 RemoteObjects,我无法更改闪存端,它使用 NetConnection 的方式与我在上面显示的方式一样

标签: .net asp.net-mvc actionscript-3 flash amf


【解决方案1】:

我没有完整的答案,但这可以在一开始就帮助你。

您可以使用 FluorineFx,这是一个良好的开端,因为它实现了所有 AMF 内容,并且具有 AMFWriter/Reader、AMFDeserializer 等,可以使用它们。

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();
}

这只是第一部分。返回二进制数据和东西可以通过某种自定义 ActionResult 来处理,但是你知道从这里AMF ActionResult for asp.net mvc 怎么做吗?

祝你好运。

【讨论】:

  • 谢谢,它可以工作,除了当我发送一个对象时,我在c#端得到一个字典,你知道是否可以反序列化成一个对象?
  • 好的,找到了这个,我用了这个:fluorinefx.com/docs/fluorine/classmappingas3.html 现在它将 as 对象映射到 .net
  • @ChuckNorris 类映射和别名,是的!并且您可以在通过 IExternalizable 使用自定义序列化时节省一些流量(但是当您无法更改客户端时不是您的情况)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多