Flex调用C# Webservice
终于试出flex用WebService的方式取得组件的数据系结。后端用Turbo C#开新WebService专案,贴上下面二个简单的Method
public string [] HelloWorld(){ string [] arr=new string; arr="字符串A"; arr="字符串二"; arr="字符串三"; return arr;}public double Calc(double r) { return 2 * r * Math.PI;}
然后用 Cassini web server方式执行。前端用flex MXML Application贴上下面程序代码
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"> <mx:Script><! private var myData:ArrayCollection; private function resultHandler(event:ResultEvent):void { myData = event.result as ArrayCollection; }]]> </mx:Script> <mx:WebService id="myService"wsdl="http://127.0.0.1:8080/WebServiceApplication3/WebService1.asmx?wsdl"><mx:operation name="HelloWorld" result="resultHandler(event)"/> <mx:operation name="Calc"> <mx:request> <r>{radius.text}</r> </mx:request> </mx:operation> </mx:WebService><mx:List id="myList" dataProvider="{myData}" width="206"/> <mx:Label text="{myList.selectedItem}"/> <mx:TextInput id="radius"/> <mx:Button label="取得数组" click="myService.HelloWorld.send()"/> <mx:Text text="{myService.Calc.lastResult}" /> <mx:Button label="计算" click="myService.Calc.send();"/> </mx:Application> 执行之后,便用WebService方式向后端取得HelloWorld及Calc二个method的回传值。关键点在lastResult若是数组需以as ArrayCollection转型成ArrayCollection来承接。
页:
[1]