AMF3 + AS 3.0 + ASP.NET 完整配置过程

我使用的是  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 搜索吧  不懂安装的朋友  直接 QQ  :289435275

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  吧!!!

<!--++ plugin_code qcomic begin-->

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值