日期:2014-05-17  浏览次数:21018 次

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" } 别乱改哦! 等你懂了你再换其他 !

[Copy to clipboard] [ - ]
CODE:
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

[Copy to clipboard] [ - ]
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))