加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex 和webService 通讯

发布时间:2020-12-15 04:08:40 所属栏目:百科 来源:网络整理
导读:在flex中和webservice是很简单,使用Webservice类就好了。 先说一下他的使用呀 ???web=new WebService(); //这是一个webservice的地址; ??? web.wsdl = "http://www.webservicex.net/globalweather.asmx?wsdl";? ? ???web.loadWSDL(); 这样就已经连接上了.

在flex中和webservice是很简单,使用Webservice类就好了。

先说一下他的使用呀

???web=new WebService();

//这是一个webservice的地址;
??? web.wsdl = "http://www.webservicex.net/globalweather.asmx?wsdl";? ?

???web.loadWSDL();

这样就已经连接上了.

想监控连接是否成功可以注册LoadEvent.LOAD事件

???web.addEventListener(LoadEvent.LOAD,OnLoad);

下来就可以调用webservice的接口了,激动的时刻来了,如果接口有返回值的话,要先监听一下结果

?

???web.GetCitiesByCountry.addEventListener(ResultEvent.RESULT,OnGetCity);
???web.GetCitiesByCountry("china");

??private function OnGetCity(event:ResultEvent ):void{
???var xml:XML=new XML(event.result);

??}

?

这样就可以了,很简单吧.

?

?

下面给大家一个例子,天气预报的

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script>
?<![CDATA[
??import mx.rpc.soap.LoadEvent;
??import mx.rpc.soap.WebService;
??????? import? mx.rpc.events.ResultEvent;
??[Bindable]
??private var city:Array=new Array();
??private var web:WebService;
??private function init():void{
???web=new WebService();
??????????? web.wsdl = "http://www.webservicex.net/globalweather.asmx?wsdl";? ?

???web.addEventListener(LoadEvent.LOAD,OnLoad);
???web.loadWSDL();
???web.GetCitiesByCountry.addEventListener(ResultEvent.RESULT,OnGetCity);
???web.GetCitiesByCountry("china");
???web.GetWeather.addEventListener(ResultEvent.RESULT,OnGetWeather);
??}
??
??private function OnLoad(event:Event):void{
???pnlWeather.title+="------ webservice connected ... "?
??}
??
??private function OnGetCity(event:ResultEvent ):void{
???var xml:XML=new XML(event.result);
???for each ( var name:XML in xml..City ) {
????city.push(name);
???}??
???cmbCity.selectedIndex=0;


??}
??
??private function OnGetWeather(event:ResultEvent ):void{
???txtRWeather.text="";
???var xml:XML=new XML(event.result);
???var xmlList:XMLList=xml.children();
???for (var i:int =0;i<xmlList.length();i++){
????
????txtRWeather.text+= xmlList[i].toXMLString()+"/n";
???}
??}
??
??private function OnClick():void{
????web.GetWeather(cmbCity.selectedLabel,"china");??
??}
?]]>
</mx:Script>
<mx:Panel title="Weather"? height="262" width="421" layout="absolute" id="pnlWeather">
?<mx:Label text="city:" x="74" y="24"/>
?<mx:ComboBox x="130" y="24" width="106" id="cmbCity" dataProvider="{city}"></mx:ComboBox>
?<mx:Button x="258" y="24" label="提交" click="OnClick()"/>
?<mx:TextArea x="130" y="54" width="261" height="156" id="txtRWeather"/>
?<mx:Label x="74" y="53" text="weather"/>

?

</mx:Panel> </mx:Application>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读