如果WebService返回的数据为DataTable或List<>类型,可以在每次读取数据的时候加入断点,然后观察最终生成数据的结构,断点最好加在ResultEvent事件内,因为这个时候才能确保从WebService获取到了数据
下面的例子分别接收从WebService返回String、DataTable、List<>类型的数据,并作相应的处理
WebService代码(.net):
[WebMethod] string GetString(string name) {+ name; } [WebMethod(Description = )] DataTable GetDataTable() {DataTable dt = DataTable();dt.Columns.Add();dt.Columns.Add();dt.Columns.Add();DataRow dr = dt.NewRow();dr[] = 1;dr[] = ;dr[] = ;dt.Rows.Add(dr);dr = dt.NewRow();dr[] = 2;dr[] = ;dr[] = ;dt.Rows.Add(dr);dt; } [WebMethod(Description = )] List<Music> GetList() {List<Music>{Music{ID = 3,Song = ,Artist = },Music{ID = 4,Song = ,Artist = }}; }
Flex代码:
<?xml version= encoding=?> <mx:Application xmlns:mx= layout=><mx:Script><![CDATA[mx.rpc.soap.mxml.Operation;mx.controls.Alert;mx.rpc.events.FaultEvent;mx.rpc.events.ResultEvent;mx.rpc.soap.WebService;onResult(evt:ResultEvent):{funcName:String = evt.target.name;(funcName){:Alert.show(evt.result.toString());break;:myGrid.dataProvider = ws1.GetDataTable.lastResult.Tables.MusicList.Rows;break;:myGrid.dataProvider = ws1.GetList.lastResult;break;}}onFault(evt:FaultEvent):{Alert.show(evt.fault.faultDetail.toString());}]]></mx:Script><mx:WebService id= wsdl=><mx:operation name= result= fault=><mx:request><name>臣本布衣</name></mx:request></mx:operation><mx:operation name= result= fault= /><mx:operation name= result= fault= /></mx:WebService><mx:DataGrid id= x= y=><mx:columns><mx:DataGridColumn headerText= dataField=/><mx:DataGridColumn headerText= dataField=/><mx:DataGridColumn headerText= dataField=/></mx:columns></mx:DataGrid><mx:Button label= click= x= y=></mx:Button><mx:Button label= click= x= y=></mx:Button><mx:Button label= click= x= y=></mx:Button> </mx:Application>