`
hereson
  • 浏览: 1428741 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

AMF3 + AS 3.0 + ASP.NET 完整配置过程及源文件

    博客分类:
  • fms2
阅读更多

AMF3 + AS 3.0 + ASP.NET 完整配置过程及源文件

 

还在用 AMF0?  还在用 XML传数据? 还在抱怨 byteArray 要转换成 base64 ? 还在苦恼 fms 生成图片的高消耗和低效率?

// fms 2 其他都很好 我就说这一点不好 跟贴的别乱来!

 

跟我用超帅的 AMF3 吧! 

// 这次转牛角尖  找资料: 历时4 天  浏览过的贴子:无数  找到范例数:0  // 盛怒之下  决定自己写!!!

 

我使用的是  Fluorine Gateway      

这个软件的优点是 绝对免费 且无任何限制 数据类型支持面广

从这个网址下载fluorine.exe 并安装它 

官网: http://fluorine.thesilentgroup.com/index.htm

 

 

第一步 

打开    Microsoft Visual Web Developer 2005 速成版  (我用免费的 其他版本都一样)

新建一个 网站  选择模板[A project for creating a Fluorine enabled ASP.NET Web application]

命名为 “fluorine”  // 必需用这个! 等你懂了你再换其他 别给我捣乱

 

在 fluorines 网站的“解决方案资源管理器”里面你会看到

 

1) bin 文件夹  里面就是  Fluorine的核心    支持 AMF3和 AMF0 的 DLL 动态连接库

2) Gateway.aspx  这是默认的    不用改  里面也差不多是空的 它的存在仅仅是为了  建立一个 AS3的 NetConnection

3) web.config和 WEB-INF文件夹里的那两个文件  不是我们菜鸟能看得懂的 但是是关键和必须的 也不需要你改 

4) App_Code 文件夹 我们只需要弄这个   把我们自己写的 *.cs文件放到这里 就可以  用NetConnection.call

来实现里面的 function 了

 

第二步

 

加代码    C# 的    放在 App_Code 文件夹 里面 

 

文件名 { "KitaRemoting.cs" } 别乱改哦! 等你懂了你再换其他 !

 

 

 

using System;

using System.IO;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Drawing;

using System.Drawing.Imaging;

using com.TheSilentGroup.Fluorine;

using com.TheSilentGroup.Fluorine.AMF3;

//你要使用其他AS3的数据类型就在那个 Bin/com.TheSilentGroup.Fluorine.dll 文件里面慢慢找吧! 

namespace fluorine

{

    /// <summary>

    /// Fluorine sample service.

    /// </summary>

    [RemotingService("Fluorine sample service")]

    public static class KitaRemoting

    {

        public static string Echo(string text)

        {

            return "Gateway echo: " + text;

        }

        public static String SaveImage(ByteArray byteArray, String fileName)

        {

            uint length = byteArray.Length;

            byte[] bytes = new byte[length];

            byteArray.ReadBytes(bytes, 0, length);

            MemoryStream ms = new MemoryStream(bytes);

            System.Drawing.Image img = System.Drawing.Bitmap.FromStream(ms);

            Bitmap bmp = new Bitmap(img);

            //To save the image to a file

            MemoryStream tempStream = new MemoryStream();

            bmp.Save(tempStream, System.Drawing.Imaging.ImageFormat.Jpeg);

            FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath(fileName), FileMode.Create);

            tempStream.WriteTo(fs);

            tempStream.Close();

            fs.Close();

            tempStream.Dispose();

            fs.Dispose();

            //GC.Collect();

            return "Gateway SaveImage Finish!";

        }

    }

}

 

 

 

第三步

 

再做一个  as3 文件   你有安装 com.adobe.images.JPGEncoder这个类吗  在一个叫corelib-.90的压缩包里面  上 google code 搜索吧 

 

 

 

import flash.net.NetConnection;

import com.adobe.images.JPGEncoder;

var nc:NetConnection = new NetConnection();

nc.client = nc;

nc.objectEncoding = flash.net.ObjectEncoding.AMF3;

// 没错 你用的是  flash.net.ObjectEncoding.AMF3   帅吧!

nc.connect ("http://localhost/fluorine/Gateway.aspx");

bt.addEventListener (MouseEvent.CLICK,clickHandler);

function clickHandler (evt:MouseEvent)

{

    var time:uint =  getTimer();

    var bmd:BitmapData = new BitmapData(400,400,false,0xFFFFFFFF);

    bmd.draw (pic);

    

    var JPG:JPGEncoder = new JPGEncoder(30);

    var bary:ByteArray = JPG.encode(bmd);

    var name:String = "a.jpg";

    nc.call ("fluorine.KitaRemoting.SaveImage",new Responder(Result,Status),bary,name);

    bmd.dispose ();

    trace("Excute Time: "+String(getTimer()-time));

}

function Result (re:String)

{

    trace (re);

    trace ("成功!");

}

function Status (re:Boolean)

{

    trace ("错误!");

}

 

 

 

flash文件 你放在哪里都行  

测试 看看 !~

 

 

运行时间  Excute Time: 937

图片大小  400*400  20kb

 

实际flash 至 C# 数据传输长度  16065    取自 [Microsoft Visual Web Developer 2005 ] 调试结果 二进制数组长度

 

 

摆脱 虚伪的 base64  踢走AMF0  吧!!!

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics