Net与Flex入门
?????FluorineFx官方提供了安裝包的下載和在線文檔,可以幫助我們有效的利用FluorineFx來開發。?
?????FluroineFx官方網站:http://www.fluorinefx.com/????
?????FluroineFx下載地址:http://www.fluorinefx.com/download.html
?????FluroineFx在線文檔:http://www.fluorinefx.com/docs/fluorine/index.html
?
一、服務端的開發
??? 1、通過Microsoft Visual Studio 2008 創建創建解決方案,并添加FluroineFx服務器庫
??????? ?路徑:E:\FlexDemo\FlexDemoTest1\ServiceLibrary1
??? 2、添加FluorineFx 網站到解決方案,添加成功后網站會自動引用FluorineFx服務庫的dll
???????? 路徑:E:\FlexDemo\FlexDemoTest1\WebSite1
????3、結構如下:??
?
?4、代碼如下:
?
namespace ServiceLibrary1
{
??? /// <summary>
??? /// Fluorine sample service.
??? /// </summary>
??? [RemotingService("Fluorine sample service")]
??? public class Sample
??? {
??????? public Sample()
??????? {
??????? }
??????? public string Echo(string text)
??????? {
??????????? return "Gateway echo: " + text;
??????? }
??????? public Contact GetContact()
??????? {
??????????? Contact c = new Contact { Name = "Fred", Email = "fred@example.com", Phone = "555-1212" };
??????????? return c;
??????? }
??????? public FluorineFx.AMF3.ArrayCollection GetContacts()
??????? {
??????????? FluorineFx.AMF3.ArrayCollection result =
??????????????? new FluorineFx.AMF3.ArrayCollection{
??????????????????? new Contact { Name = "Fred", Email = "fred@example.com", Phone = "555-1212" },
??????????????????? new Contact { Name = "Jane", Email = "jane@example.com", Phone = "555-1213" },
??????????????????? new Contact { Name = "Bob", Email = "bob@example.com", Phone = "555-1214" }};
??????????? return result;
??????? }
??????? /// <summary>
??????? /// 獲取服務端的系統時間
??????? /// </summary>
??????? /// <returns></returns>
??????? public string GetServerTime()
??????? {
??????????? return DateTime.Now.ToString();
??????? }
??????? public ArrayCollection GetBooks()
??????? {
??????????? ArrayCollection array = new ArrayCollection();
??????????? array.Add(new Book(1, "三國演義", "羅貫中", 100.00));
??????????? array.Add(new Book(2, "西游記", "吳承恩", 200.00));
??????????? array.Add(new Book(3, "水滸傳", "施耐庵", 300.00));
??????????? array.Add(new Book(4, "紅樓夢", "曹雪芹", 400.00));
??????????? return array;
??????? }
??? }
??? [FluorineFx.TransferObject]
??? public class Book
??? {
??????? public int ID { get; set; }
??????? public string Name { get; set; }
??????? public string Author { get; set; }
??????? public double Price { get; set; }
??????? public Book()
??????? { }
??????? public Book(int id, string name, string author, double price)
??????? {
??????????? this.ID = id;
??????????? this.Name = name;
??????????? this.Author = author;
??????????? this.Price = price;
??????? }
??? }
}
?
二、客戶端開發
?? 1、首先創建Flex項目
???????Project location? Floder設置為:E:\FlexDemo\FlexDemoTest1\WebSite1\flex4
???????Application type設置為:Web application,Application
???2、??? Flex項目創建完畢,下面在通過一些相應的配置就可以通過FluorineFx和.NET通信了。開發項目屬性設置面板,設置
????Flex?? Complier:? ?-locale en_US -services "..\..\WEB-INF\flex\services-config.xml"? -context-root "/WebSite1"
??? Flex Build Path:
???????????????? output folder url:http://localhost:7217/WebSite1/flex4/bin-debug(注意路徑大小寫)
?? 3、代碼如下
?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
?<mx:RemoteObject id="service" destination="fluorine"
???? source="ServiceLibrary1.Sample">
???????? <mx:method name="Echo" result="onResult1(event)">
???????? </mx:method>
?</mx:RemoteObject>
????? 
????? <mx:Script>
???????? <![CDATA[
??????????? import mx.rpc.events.ResultEvent;
??????????? import mx.collections.ArrayCollection;
??????????? import mx.controls.List;
??????????? import mx.rpc.events.FaultEvent;
??????????? import mx.rpc.events.ResultEvent;
??????????? private var nc:NetConnection;
??????????? private var rs:Responder;
??????????? private var rs1:Responder;
??????????? private function init():void
??????????? {
??????????????? nc = new NetConnection();
??????????????? rs = new Responder(onResult,onStatus);
??????????????? rs1=new Responder(onResult1,onStatus);
??????????????? nc.objectEncoding = ObjectEncoding.AMF3;
??????????????? nc.connect("http://localhost:7217/WebSite1/Gateway.aspx");
??????????????? nc.client = this;
??????????? }
??????????? private function onResult(result:String):void
??????????? {
??????????????? this.lbServerTime.text = "服務端系統時間為:" + result;
??????????? }
??????????? private function onStatus(event:Object):void
??????????? {
??????????????? trace("Error");
??????????? }
??????????? private function getServerTime(event:MouseEvent):void
??????????? {
??????????????? //服務器端所提供的RemotingService的全限定名
??????????????? nc.call("ServiceLibrary1.Sample.GetServerTime",rs);
??????????? } 
???????? internal function onClick():void
???????? {
???????????? service.Echo(txtInput.text);
?????????? 
???????? }
????????? 
????????? internal function onResult1(evt:ResultEvent):void
???????? {
???????????? txtResult.text = evt.result.toString();
???????? }
???????? ]]>
???? </mx:Script>
???? 
???? <mx:Panel x="53" y="52" width="473" height="361" layout="absolute" title="FluorineFx" fontSize="12">
???????? <mx:TextInput x="35" y="21" id="txtInput"/>
???????? <mx:Button x="35" y="63" label="確 定" fontWeight="normal" click="onClick()"/>
???????? <mx:Label x="35" y="95" text="結 果:"/>
???????? <mx:TextInput x="35" y="123" width="160" id="txtResult"/>
???????? <mx:Button x="35" y="176" label="獲取服務器系統時間" click="getServerTime(event)"/>
???????? <mx:Label x="23" y="249" width="402" id="lbServerTime"/>
???????? <mx:Button x="237" y="125" label="Button"/>
???? </mx:Panel>
???? 
</mx:Application>
?
?
轉載于:https://www.cnblogs.com/yidianfeng/archive/2011/11/02/2233029.html
總結
以上是生活随笔為你收集整理的Net与Flex入门的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 菜鸟修炼C语言小设计之——工资统计
 - 下一篇: oop1