1.使用Flex绑定Web Service必须保证WebService可用情况下使用
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" >
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.soap.LoadEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
private var dataList:ArrayCollection;
[Bindable]
private var tmp:String;
//事件绑定处理方法
private function resultHandler(event:ResultEvent):void
{
tmp=event.result as String;
Alert.show("tmp="+tmp);
}
//错误处理方法
private function faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.faultDetail);
}
]]>
</mx:Script>
<mx:WebService id="weatherWs" wsdl="http://localhost:8090/FlexWS/services/FlexWebService?wsdl" >
//默认的参数必须:in0 ,in1,.......
<mx:operation name="helloWord" result="resultHandler(event)" fault="faultHandler(event)">
<mx:request>
<in0>
xiaoxiao
</in0>
<in1>
ZH
</in1>
</mx:request>
</mx:operation>
</mx:WebService>
<mx:Button label="查看信息" click="weatherWs.helloWord()" x="169" y="10"/>
<!--表达式-->
<mx:Label text="{weatherWs.helloWord.lastResult}" y="12"/>
</mx:Canvas>
源代码如下: