日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Flex調(diào)用Webservice實現(xiàn)天氣預(yù)報

你對Flex調(diào)用Webservice實現(xiàn)天氣預(yù)報的方法是否熟悉,這里和大家分享一下,F(xiàn)lex調(diào)用Webservice有多種方法,可以通過ActionScript中Webservice類來實現(xiàn)。還有就是使用組件實現(xiàn)。

成都創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站設(shè)計、成都做網(wǎng)站與策劃設(shè)計,西林網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十多年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:西林等地區(qū)。西林做網(wǎng)站價格咨詢:18980820575

Flex調(diào)用Webservice實現(xiàn)天氣預(yù)報

Flex調(diào)用Webservice有多種方法,可以通過FlexBuilder提供的管理Webservices的工具解析WSDL文檔生成本地調(diào)用類。也可以通過ActionScript中Webservice類來實現(xiàn)。還有就是使用組件實現(xiàn)。這次我使用的是最后一種,感覺這種方法較為簡潔。

1.構(gòu)建界面

用于接受用戶輸入及結(jié)果輸出。包括:1個Text輸入組件,1個按鈕組件,10個標(biāo)簽組件

2.添加Webservice組件

根據(jù)Web服務(wù)提供者的說明,構(gòu)建Webservice組件。代碼如下:

 
 
 
  1. WebServices/WeatherWebService.asmx?wsdl"  
  2. useProxy="false"showBusyCursor="true"> 
  3. result="resultOK()"> 
  4.  
  5.  
  6. {city.text.toString()}  
  7.  
  8.  
  9.  
  10.  

注意:operation組件中的name屬性需要和待使用的方法的名字相同。result的屬性是在調(diào)用方法成功后執(zhí)行的ActionScript方法。operation還有其他屬性,鑒于例子很簡單,就不一一使用了。

3.編寫ActionScript方法

本例中使用了三個方法:resultOK()用于顯示結(jié)果的,showMessage()用于顯示說明,getfocus()用于當(dāng)輸入欄得到焦點時清空輸入欄內(nèi)容的。下面是resultOK()的分析:

 
 
 
  1. publicfunctionresultOK():void{//顯示接受的結(jié)果  
  2. arrayResult=newArrayCollection();  
  3. arrayResult=ws.getWeatherbyCityName.lastResult;  
  4.  
  5. //顯示今天的情況  
  6. jin1.text=arrayResult[6].toString().substring(0,arrayResult[6].toString().indexOf(""));  
  7. jin2.text=arrayResult[6].toString().substring((arrayResult[6].toString().indexOf(""))+1);  
  8. jin3.text=arrayResult[5];  
  9. jin4.text=arrayResult[7];  
  10.  
  11. //顯示明天的情況  
  12. ming1.text=arrayResult[13].toString().substring(0,arrayResult[13].toString().indexOf(""));  
  13. ming2.text=arrayResult[13].toString().substring((arrayResult[13].toString().indexOf(""))+1);  
  14. ming3.text=arrayResult[12];  
  15. ming4.text=arrayResult[14];  
  16.  
  17. //顯示后天的情況  
  18. hou1.text=arrayResult[18].toString().substring(0,arrayResult[18].toString().indexOf(""));  
  19. hou2.text=arrayResult[18].toString().substring((arrayResult[18].toString().indexOf(""))+1);  
  20. hou3.text=arrayResult[17];  
  21. hou4.text=arrayResult[19];  
  22. }  
  23.  

在使用Web服務(wù)返回的結(jié)果時,發(fā)現(xiàn)其結(jié)果保存在字符數(shù)組中的,在WSDL中是ArrayOfString,而Flex沒有這種格式,在試過String,Array類型后,發(fā)現(xiàn)ArrayCollection類可以使用。然后就是顯示結(jié)果,可根據(jù)WSDL說明來挑選信息。

4.使用按鈕調(diào)用Webservice組件,發(fā)送Web服務(wù)信息。

即調(diào)用ws.getWeatherbyCityName.send()方法。

◆編譯發(fā)布swf文件

求助:在使用swf文件的時候有這樣的問題,不曉得怎么把flex導(dǎo)出的swf嵌入Html中。普通的嵌入,不能實現(xiàn)調(diào)用Web服務(wù)的功能,使用項目生成的文件包中的Html文件倒是可以,但是如果把文件包復(fù)制出來,放到另外的地方,又無法使用Web服務(wù)了。那位高手能夠給予幫助,在下將不勝感激。

完整代碼如下:

 
 
 
  1.  
  2. height="155"layout="absolute"fontSize="12"viewSourceURL="srcview/index.html"> 
  3.  
  4. importmx.controls.Alert;  
  5. importmx.collections.ArrayCollection;  
  6. publicvararrayResult:ArrayCollection;//保存接收到的結(jié)果  
  7. publicfunctionresultOK():void{//顯示接受的結(jié)果  
  8. arrayResult=newArrayCollection();  
  9. arrayResult=ws.getWeatherbyCityName.lastResult;  
  10.  
  11. //顯示今天的情況  
  12. jin1.text=arrayResult[6].toString().substring(0,arrayResult[6].toString().indexOf(""));  
  13. jin2.text=arrayResult[6].toString().substring((arrayResult[6].toString().indexOf(""))+1);  
  14. jin3.text=arrayResult[5];  
  15. jin4.text=arrayResult[7];  
  16.  
  17. //顯示明天的情況  
  18. ming1.text=arrayResult[13].toString().substring(0,arrayResult[13].toString().indexOf(""));  
  19. ming2.text=arrayResult[13].toString().substring((arrayResult[13].toString().indexOf(""))+1);  
  20. ming3.text=arrayResult[12];  
  21. ming4.text=arrayResult[14];  
  22.  
  23. //顯示后天的情況  
  24. hou1.text=arrayResult[18].toString().substring(0,arrayResult[18].toString().indexOf(""));  
  25. hou2.text=arrayResult[18].toString().substring((arrayResult[18].toString().indexOf(""))+1);  
  26. hou3.text=arrayResult[17];  
  27. hou4.text=arrayResult[19];  
  28. }  
  29.  
  30. //顯示說明  
  31. publicfunctionshowMessage():void{  
  32. varalert:Alert=Alert.show("請輸入城市中文名稱(國外城市可用英文)。web服務(wù)來源于http://www.webxml.com.cn,數(shù)據(jù)來源于中國氣象局"+  
  33. ",包括340多個中國"+  
  34. "主要城市和60多個國外主要城市三日內(nèi)的天氣情況。作者EMAIL:anhulife@gmail.com","說明",Alert.YES);  
  35. }  
  36.  
  37. //處理當(dāng)輸入欄獲得焦點時,輸入欄清空  
  38. publicfunctiongetfocus():void{  
  39. city.text="";  
  40. }  
  41. ]]> 
  42.  
  43.  
  44.  
  45. useProxy="false"showBusyCursor="true"> 
  46.  
  47.  
  48.  
  49. {city.text.toString()}  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. width="200"x="10"y="10"focusIn="getfocus()"fontSize="12"color="#909697"/> 
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  

 想學(xué)習(xí)Webservice,所以先研究一下Flex怎么調(diào)用WebService.看了這篇文章感覺不錯,先測試一下。


網(wǎng)站名稱:Flex調(diào)用Webservice實現(xiàn)天氣預(yù)報
文章源于:http://www.dlmjj.cn/article/dhihodo.html