本文主要是介绍flex webservice获取城市的天气情况,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute"><mx:Style>global{fontSize:12pt;}</mx:Style><mx:Script><![CDATA[import mx.collections.ArrayCollection;import mx.controls.Alert;import mx.rpc.events.FaultEvent;import mx.rpc.events.ResultEvent;//引入远程调用的事件处理//向WebService发送请求private function sendCount():void{ws.getWeather.send();}//显示结果的处理函数private function showResult(rs:ResultEvent):void{//得到返回的结果var rsStr:ArrayCollection=ArrayCollection(rs.result);var info:String = "";for(var i:int=0;i<rsStr.length;i++) {info+=rsStr[i]+"\n";}Alert.show(info);cityInfoText.text=rsStr[0];}private function faultResult(faultmessage:FaultEvent):void{var faultStr:String=new String(faultmessage.message);Alert.show(faultStr, "WebService访问错误");}private function go():void{navigateToURL(new URLRequest("http://www.webxml.com.cn/"), "_blank");}//清空查询信息private function clearText():void{cityCode.text=null;userid.text=null;}]]></mx:Script><!-- 引入WebService标签,设定wsdl。不使用代理名称--><!--此 WebService由网站:http://www.webxml.com.cn/提供。该网站内还有其它免费web服务 --><mx:WebService id="ws"wsdl="http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl"useProxy="false"showBusyCursor="true"result="showResult(event)"fault="faultResult(event)"><mx:operation name="getWeather" resultFormat="object"><mx:request><theCityCode>{cityCode.text}</theCityCode><theUserID>{userid.text}</theUserID></mx:request></mx:operation></mx:WebService><mx:Panel x="296"y="107"width="364"height="277"layout="absolute"title="城市天气查询"horizontalAlign="center"verticalAlign="middle"><mx:TextInput x="127"y="33"id="cityCode"/><mx:Button x="114"y="182"label="查询"click="sendCount()"/><mx:Text x="35"y="154"text=""width="299"id="cityInfoText"/><mx:Button x="174"y="182"label="清除"id="clear"click="clearText()"/><mx:TextInput x="127" y="78" id="userid"/><mx:Label x="35" y="35" text="城市ID/城市名"/><mx:Label x="35" y="80" text="UserId"/></mx:Panel><mx:Text width="321"height="50"x="318"y="37"><mx:htmlText><![CDATA[<a href="http://blog.163.com/liwei3324@126/" target=" _blank">如有不懂的地方,欢迎访问我的博客。点击我</a>]]></mx:htmlText></mx:Text><mx:Label x="135"y="403"text="此WebService是由网站http://www.webxml.com.cn/提供"fontSize="22"fontWeight="bold"fontStyle="italic"/><mx:LinkButton x="404"y="458"label="走,去看看!>>"color="#1510EC"click="go()"/>
</mx:Application>
这篇关于flex webservice获取城市的天气情况的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!