日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

[原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (三)

發(fā)布時間:2025/7/14 asp.net 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (三) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

版權(quán)由http://xingfustar.cnblogs.com/所有,轉(zhuǎn)載請注明出處,XingFuStar 2007年12月14日

五、復(fù)雜數(shù)據(jù)類型的通訊(http://xingfustar.cnblogs.com/)
????
????Remoting支持傳送數(shù)組、List、HashTable、Dictionary等多種復(fù)雜數(shù)據(jù)類型,本文以數(shù)組,Dictionary,HashTable為例,講解復(fù)雜數(shù)據(jù)類型的通訊。

(一)數(shù)組(http://xingfustar.cnblogs.com/)

1、.NET服務(wù)器端程序(http://xingfustar.cnblogs.com/)

????假設(shè)我們要做段程序,來獲取所有的用戶姓名。修改上節(jié)中的代碼,增加一個GetUsers方法。代碼如下:
????????public?string[]?GetArray()
????????{
????????????
string[]?array?=?new?string[]{"張三","李四","王五"};

????????????
return?array;
????????}

2、Flex客戶端程序(http://xingfustar.cnblogs.com/)

????在 Design 模式下添加,添加一個 Text文本控件,id為txtUsers,txt屬性為空,添加一個 Button控件,id為btnGetArray,Label屬性為?GetArray
????
????在 Source 模式下, 修改 mx:RemoteObject 標(biāo)簽,添加 
????<mx:method name="GetArray" result="RemoteResult(event)" fault="RemoteFault(event)"/>?
????修改腳本中 RemoteResult 方法,增加一個Case條件,代碼如下
????????????public?function?RemoteResult(re:ResultEvent):void
????????????{?
????????????????
switch(re.currentTarget.name)
????????????????{
????????????????????
case?"HelloWord":
????????????????????????var?str:String?
=?re.result?as?String;
????????????????????????
this.txtHelloWord.text?=?str;
????????????????????????
break;
????????????????????
case?"SayHello":
????????????????????????str?
=?re.result?as?String;
????????????????????????
this.txtSayHello.text?=?str;
????????????????????????
break;
????????????????????
case?"GetArray":
????????????????????????
for(var?i:int=0;?i<re.result.length;?i++)
????????????????????????{
????????????????????????????
this.txtUsers.text?+=?re.result[i].toString()?+?",?";
????????????????????????}
????????????????????????
break;
????????????????}
????????????}
????在 mx:Button (GetArray?標(biāo)簽中添加屬性 click="sampleRemoteObject.GetArray()"

????運行Flex程序,在瀏覽器中查看效果 

(二)Dictionary(http://xingfustar.cnblogs.com/)

1、.NET服務(wù)器端程序(http://xingfustar.cnblogs.com/)

????接下來我們做個Dictionary的例子,假設(shè)上例中,我們不光要獲取用戶姓名,而且我們還要得到他對應(yīng)的年齡,我們使用Dictionary。修改代碼,添加如下方法:
????????public?Dictionary<String,?Int32>?GetDictionary()
????????{
????????????Dictionary
<String,?Int32>?age?=?new?Dictionary<string,?int>();
????????????age.Add(
"張三",?23);
????????????age.Add(
"李四",?24);
????????????age.Add(
"王五",?22);
????????????
return?age;
????????}

2、Flex客戶端程序(http://xingfustar.cnblogs.com/)

????在 Design 模式下添加,添加六個 Text文本控件,屬性分別為 id = txtZhangSan,txt = ""; id = txtLiSi,txt = ""; id = txtWangWu,txt = ""; txt = "張三:"; txt = "李四:"; txt = "王五:"
????添加一個 Button控件,id為btnGetDictionary,Label屬性為?GetDictionary
????
????在 Source 模式下, 修改 mx:RemoteObject 標(biāo)簽,添加 
????<mx:method name="GetDictionary" result="RemoteResult(event)" fault="RemoteFault(event)"/>?
????修改腳本中 RemoteResult 方法,增加一個Case條件,代碼如下
????????????public?function?RemoteResult(re:ResultEvent):void
????????????{?
????????????????
switch(re.currentTarget.name)
????????????????{
????????????????????
case?"HelloWord":
????????????????????????var?str:String?
=?re.result?as?String;
????????????????????????
this.txtHelloWord.text?=?str;
????????????????????????
break;
????????????????????
case?"SayHello":
????????????????????????str?
=?re.result?as?String;
????????????????????????
this.txtSayHello.text?=?str;
????????????????????????
break;
????????????????????
case?"GetUsers":
????????????????????????
for(var?i:int=0;?i<re.result.length;?i++)
????????????????????????{
????????????????????????????
this.txtUsers.text?+=?re.result[i].toString()?+?",?";
????????????????????????}
????????????????????????
break;
????????????????????
case?"GetDictionary":
????????????????????????
this.txtZhangSan.text?=?re.result["張三"];
????????????????????????
this.txtLiSi.text?=?re.result["李四"];
????????????????????????
this.txtWangWu.text?=?re.result["王五"];
????????????????????????
break;
????????????????}
????????????}
????在 mx:Button (GetDictionary)?標(biāo)簽中添加屬性 click="sampleRemoteObject.GetDictionary()"

????運行Flex程序,在瀏覽器中查看效果 


(三)HashTable(http://xingfustar.cnblogs.com/)

1、.NET服務(wù)器端程序(http://xingfustar.cnblogs.com/)

????我們將上例中的Dictionary類型改成HashTable類型,代碼如下:
????????public?Hashtable?GetHashTable()
????????{
????????????Hashtable?hash?
=?new?Hashtable();
????????????hash.Add(
"張三",?23);
????????????hash.Add(
"李四",?24);
????????????hash.Add(
"王五",?22);
????????????
return?hash;
????????}

2、Flex客戶端程序(http://xingfustar.cnblogs.com/)

????借用下上例內(nèi)容,在 Design 模式下添加一個 Button控件,id為btnGetHashTable,Label屬性為?GetHashTable
????
????在 Source 模式下, 修改 mx:RemoteObject 標(biāo)簽,添加 
????<mx:method name="GetHashTable" result="RemoteResult(event)" fault="RemoteFault(event)"/>?
????修改腳本中 RemoteResult 方法,只需在上例? case "GetDictionary": 下一行加上 case "GetHashTable": 即可。
????????????????????case?"GetDictionary":
????????????????????
case?"GetHashTable":
????????????????????????
this.txtZhangSan.text?=?re.result["張三"];
????????????????????????
this.txtLiSi.text?=?re.result["李四"];
????????????????????????
this.txtWangWu.text?=?re.result["王五"];
????????????????????????
break;

????在 mx:Button (GetHashTable)?標(biāo)簽中添加屬性 click="sampleRemoteObject.GetHashTable()"

????運行Flex程序,在瀏覽器中查看效果 

附件:完整代碼(http://xingfustar.cnblogs.com/)
1、.NET端

/*----------------------------------------------------------------
?*?版權(quán):
http://XingFuStar.cnblogs.com
?*?
?*?文件名:?RemotingSample
?*?文件功能描述:?.NET與Flex通訊DEMO
?*?
?*?作者:XingFuStar
?*?日期:2007年12月11日
?*?
?*?當(dāng)前版本:V1.0.0
?*?
?*?修改日期:2007年12月14日
?*?修改內(nèi)容:增加獲取數(shù)組,Dictionary,HashTable等方法例程
?*---------------------------------------------------------------
*/

using?System;
using?com.TheSilentGroup.Fluorine;
using?System.Collections.Generic;
using?System.Collections;

namespace?RemotingSample
{
????[RemotingService(
"Fluorine?sample?service")]
????
public?class?RemotingSample
????{
????????
public?RemotingSample()
????????{
????????????
//請不要刪除以下信息
????????????
//版權(quán):http://XingFuStar.cnblogs.com
????????}

????????
public?string?HelloWord()
????????{
????????????
return?"Hello?Word!";
????????}

????????
public?string?SayHello(string?name)
????????{
????????????
return?"Hello?"?+?name?+?"!";
????????}

????????
public?string[]?GetArray()
????????{
????????????
string[]?array?=?new?string[]{"張三","李四","王五"};

????????????
return?array;
????????}

????????
public?Dictionary<String,?Int32>?GetDictionary()
????????{
????????????Dictionary
<String,?Int32>?dictionary?=?new?Dictionary<string,?int>();
????????????dictionary.Add(
"張三",?23);
????????????dictionary.Add(
"李四",?24);
????????????dictionary.Add(
"王五",?22);
????????????
return?dictionary;
????????}

????????
public?Hashtable?GetHashTable()
????????{
????????????Hashtable?hash?
=?new?Hashtable();
????????????hash.Add(
"張三",?23);
????????????hash.Add(
"李四",?24);
????????????hash.Add(
"王五",?22);
????????????
return?hash;
????????}
????}
}

2、Flex端

<?xml?version="1.0"?encoding="utf-8"?>
<!--
*?版權(quán):http://XingFuStar.cnblogs.com
*
*?作者:XingFuStar
*?日期:2007年12月11日
*
*?修改日期:2007年12月14日
*?修改內(nèi)容:增加獲取數(shù)組,Dictionary,HashTable等方法例程。
-->
<mx:Application?xmlns:mx="http://www.adobe.com/2006/mxml"?layout="absolute">

????
<mx:Script>
????????
<![CDATA[
????????????import?mx.rpc.events.FaultEvent;
????????????import?mx.rpc.events.ResultEvent;
????????????import?mx.controls.Alert;
????????
????????????public?function?RemoteResult(re:ResultEvent):void
????????????{?
????????????????switch(re.currentTarget.name)
????????????????{
????????????????????case?"HelloWord":
????????????????????????var?str:String?=?re.result?as?String;
????????????????????????this.txtHelloWord.text?=?str;
????????????????????????break;
????????????????????case?"SayHello":
????????????????????????str?=?re.result?as?String;
????????????????????????this.txtSayHello.text?=?str;
????????????????????????break;
????????????????????case?"GetArray":
????????????????????????for(var?i:int=0;?i<re.result.length;?i++)
????????????????????????{
????????????????????????????this.txtUsers.text?+=?re.result[i].toString()?+?",?";
????????????????????????}
????????????????????????break;
????????????????????case?"GetDictionary":
????????????????????case?"GetHashTable":
????????????????????????this.txtZhangSan.text?=?re.result["張三"];
????????????????????????this.txtLiSi.text?=?re.result["李四"];
????????????????????????this.txtWangWu.text?=?re.result["王五"];
????????????????????????break;
????????????????}
????????????}
????????
????????????public?function?RemoteFault(re:FaultEvent):void
????????????{
????????????????Alert.show("Message:"?+?re.fault.faultString,"出錯");
????????????}???????????
????????
]]>
????
</mx:Script>

????
<!--這里Source?對應(yīng).NET類,前面是命名空間,后面是類名?source?=?命名空間.類名-->
????
<mx:RemoteObject?
????????
id="sampleRemoteObject"
????????destination
="fluorine"
????????source
="RemotingSample.RemotingSample"
????????showBusyCursor
="true">
????????
<!--這里是.NET中的方法,name?=?方法名?-->
????????
<mx:method?name="HelloWord"?result="RemoteResult(event)"?fault="RemoteFault(event)"/>????
????????
<mx:method?name="SayHello"?result="RemoteResult(event)"?fault="RemoteFault(event)"/>????????????
????????
<mx:method?name="GetArray"?result="RemoteResult(event)"?fault="RemoteFault(event)"/>
????????
<mx:method?name="GetDictionary"?result="RemoteResult(event)"?fault="RemoteFault(event)"/>????
????????
<mx:method?name="GetHashTable"?result="RemoteResult(event)"?fault="RemoteFault(event)"/>????????
????
</mx:RemoteObject>

????
<mx:Text?x="38"?y="25"?id="txtHelloWord"/>
????
<mx:Button?x="38"?y="51"?label="HelloWord"?id="btnHelloWord0"?click="sampleRemoteObject.HelloWord()"/>
????
????
<mx:Text?x="38"?y="105"?id="txtSayHello"/>
????
<mx:Label?x="38"?y="131"?text="name:"/>
????
<mx:TextInput?x="88"?y="129"?id="txtName"/>
????
<mx:Button?x="256"?y="129"?label="SayHello"?id="btnSayHello"?click="sampleRemoteObject.SayHello(this.txtName.text)"/>
????
????
<mx:Text?x="38"?y="181"?id="txtUsers"/>
????
<mx:Button?x="38"?y="207"?label="GetArray"?id="btnGetArray"?click="sampleRemoteObject.GetArray()"/>
????
????
<mx:Label?x="38"?y="262"?text="張三:"/>
????
<mx:Text?x="76"?y="262"?id="txtZhangSan"/>
????
<mx:Label?x="129"?y="262"?text="李四:"/>
????
<mx:Text?x="167"?y="262"?id="txtLiSi"/>
????
<mx:Label?x="218"?y="262"?text="王五:"/>
????
<mx:Text?x="256"?y="262"?id="txtWangWu"/>
????
<mx:Button?x="38"?y="288"?label="GetDictionary"?id="btnGetDictionary"?click="sampleRemoteObject.GetDictionary()"/>
????
<mx:Button?x="157"?y="288"?label="GetHashTable"?id="btnGetHashTable"?click="sampleRemoteObject.GetHashTable()"/>
</mx:Application>


本節(jié)內(nèi)容到此結(jié)束,其實本節(jié)的例子都差不多,相信講到這里,看過文章的人對Remoting通訊有了大概的了解,只要熟悉AS3語言,以上這些都不困難,關(guān)于這個通訊,我計劃還有一節(jié),主要講解自定義實體對象的傳送。

如可我的文章對您有幫助,希望在轉(zhuǎn)載時保留版權(quán)及出處,謝謝!網(wǎng)友的支持是我最大的動力!

版權(quán)由http://xingfustar.cnblogs.com/所有,轉(zhuǎn)載請注明出處,XingFuStar 2007年12月14日

轉(zhuǎn)載于:https://www.cnblogs.com/XingfuStar/archive/2007/12/14/994875.html

總結(jié)

以上是生活随笔為你收集整理的[原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (三)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。