Flex连接wcf返回List<object>数据
原来用c#写的WCF服务,是使用silverlight开发的 ,在Flex也是可以调用,所以研究一下,主要是返回List<object>对象,研究了一下午,研究出来了,单击按钮,调用WCF数据。 其中最重要的是将获得的List<object>数据,定位为ArrayCollection类型: tempArr=e.result as ArrayCollection 以下为flex中的代码。 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"? xmlns:s="library://ns.adobe.com/flex/spark" ? xmlns:mx="library://ns.adobe.com/flex/mx" ? xmlns:esri="http://www.esri.com/2008/ags" ? minWidth="955" minHeight="600" ? ? > ? ?<fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.collections.Sort; import mx.collections.SortField; import mx.controls.Alert; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import services.wpsubinfo.WPSubInfo; import valueObjects.*; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//定义服务对象 var wp:WPSubInfo=new WPSubInfo();private function doClick():void? { ? ? ? ? ? ? ? ? //添加监听执行方法 wp.addEventListener(ResultEvent.RESULT,onDataTableTestResult); wp.addEventListener(FaultEvent.FAULT,onDataTableTestFault); wp.GetCitySubList("","http://localhost:1872/AirService.svc"); } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//返回失败 private function onDataTableTestFault(e:FaultEvent):void?{? Alert.show("dataTableTest调用失败,result="+ e);? trace("dataTableTest.Fault=",e);? }? public var ac:ArrayCollection = null; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//要绑定的对象 [Bindable]var tempArr:ArrayCollection; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //返回成功 private function onDataTableTestResult(e:ResultEvent):void?{?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //返回数据。 tempArr=e.result as ArrayCollection?// var a:ArrayCollection =ArrayCollection(e.result()); ?? Alert.show("aa"); //this.txtDataTable.text = "dataTableTest调用成功,结果:" ;? }? ]]> ? </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <esri:Map x="8" y="10"> <esri:ArcGISTiledMapServiceLayer url=""> </esri:ArcGISTiledMapServiceLayer> ? ?</esri:Map> <mx:TabNavigator x="95" y="168" width="284" height="200"> <s:NavigatorContent width="100%" height="100%" label="选项卡 1"> <mx:Text text="aaaa"> </mx:Text> <s:DataGrid x="10" y="29" requestedRowCount="4" ?dataProvider="{ tempArr}"> <s:columns> <s:ArrayList> <s:GridColumn dataField="C0007_SUBSTATION_ID" headerText="编号"></s:GridColumn> <s:GridColumn dataField="C0007_PNAME" headerText="名称"></s:GridColumn> </s:ArrayList> </s:columns> </s:DataGrid> <s:Button label="Call Wcf" horizontalCenter="0" id="btnCall" click="doClick()" ?bottom="10"/> </s:NavigatorContent> </mx:TabNavigator> </s:Application> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |