flex 与 java webservice通信 (二) flex篇
by SaveLearn on 二.03, 2010, under Flex, Java
这次先说一下flex的配置,eclipse版-flex3.0
flashplayer10.
其他的都不太重要了,游览器是IE8.
代码如下,基本都写了详细的注释,所以不太需要说明什么了.
请大家记住 本站地址 http://www.savelearn.com
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” xmlns:ns1=”*”>
<mx:Script>
<![CDATA[
//需要引用的类,没什么说的
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
private function sendweb():void
{
this.newservice.backstring(this.txtuname.text);
//要调用的方法名称以及要传递的参数,与上一篇中的webservice.java对应
}
private function getlist(event:ResultEvent):void
{
Alert.show(event.result.toString());
//如果调用成功的话,弹出返回的值,也就是输入到文本框里的内容加上webservice里的内容
}
private function faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.toString(),'erro');
//如果报错,弹出错误的详细信息.
}
]]>
</mx:Script>
<mx:WebService id=”newservice” wsdl=”http://localhost:8080/myjava/services/BankServiceNew?wsdl” useProxy=”false”
fault=”faultHandler(event)” >
<mx:operation name=”backstring” result=”getlist(event)” >
<mx:request>
<value>{}</value>
</mx:request>
</mx:operation>
</mx:WebService>
<mx:TextInput id=”txtuname” text=”" />
<mx:Button label=”提交” click=”sendweb()” x=”112″ y=”30″/>
</mx:Application>
保存后大家可以和前一篇一同实验一下.
有什么疑问,可以评论里说一下.