国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > WEB開發(fā) > 正文

18.8.注冊服務(wù)端數(shù)據(jù)類型

2024-04-27 13:52:26
字體:
供稿:網(wǎng)友
18.8.1. 問題
我需要在自己的應(yīng)用程序中注冊服務(wù)端數(shù)據(jù)類型,以便從RemoteObject 返回的對象能正確轉(zhuǎn)換為遠(yuǎn)程類的實例。
18.8.2. 解決辦法
使用flash.net.RegisterClass 方法或在類申明中標(biāo)記類為RemoteClass。
18.8.3. 討論
在反序列化AMF 數(shù)據(jù)中的對象為類對象時,該類必須事先在Flash Player 中注冊,這樣反序列化才能得到正確的數(shù)據(jù)類型,如下面C#定義的類型:
+展開
-C#
using System;
using System.Collections;
namespace oreilly.cookbook.vo
{
public class RecipeVO {
public string title;
public ArrayList ingredients;
public ArrayList instructions
public RecipeVO(){}
}
}

ActionScript 對應(yīng)的類型為:
+展開
-ActionScript
package oreilly.cookbook.vo
{
public class RecipeVO
public var ingredients:Array;
public var instructions:Array;
public var title:String;
public function RecipeVO(){}
}

服務(wù)將會在C#中創(chuàng)建RecipeVO 對象并返回:
+展開
-C#
using System;
using System.Web;
using oreilly.cookbook.vo;
namespace oreilly.cookbook.service
{
public class RecipeService
{
public RecipeService() { }
public RecipeVO getRecipe() {
RecipeVO rec = new RecipeVO();
rec.title = "Apple Pie";
string[] ingredients = {"flour""sugar""apples""eggs""water"};
rec.ingredients = new ArrayList(ingredients);
string[] instructions = {"instructions are long""baking is hard","maybe I'll just buy it at the store"};
rec.instruction = new ArrayList(instructions);
return rec;
}
}
}

當(dāng)服務(wù)返回時,可以這樣訪問RecipeVO:
+展開
-XML
<mx:RemoteObject id="recipeServicedestination="fluorinesource="oreilly.cookbook.FlexServiceshowBusyCursor="trueresult="roResult(event)fault="roFault(event)" />
<mx:Script>
<![CDATA[
private function initApp():void {
// we have to register the object for the result to be able to properly cast
// as the RecipeVO
flash.net.registerClassAlias("oreilly.cookbook.vo.RecipeVO", RecipeVO);
}
public function serviceResult(e:ResultEvent):void {
var rec:RecipeVO = (e.result as RecipeVO)
}
public function serviceFault(e:FaultEvent):void {
trace(" Error :: "+(e.message as String));
}

]]>
</mx:Script>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 会泽县| 大安市| 勃利县| 嵊泗县| 临沭县| 唐海县| 崇左市| 沙田区| 治多县| 台州市| 肃宁县| 黄梅县| 彩票| 垣曲县| 贵州省| 习水县| 昭苏县| 华宁县| 微博| 沧州市| 仁布县| 友谊县| 台山市| 武强县| 保亭| 出国| 巨鹿县| 建德市| 乌拉特前旗| 凤山县| 荥经县| 祥云县| 会昌县| 昔阳县| 绥德县| 抚州市| 抚州市| 嫩江县| 抚顺市| 若羌县| 贡嘎县|