Flex串連WebService–(1)

來源:互聯網
上載者:User

    前幾天配置好了Flex,接著就要開始用一用了,我參考flex的samples裡的範例打算做一個串連天氣預報服務的Flex程式,我一開始在Flex1.5裡做,結果總是提示無法串連WebService,問了網友dannyr,他說我要修改下網站目錄中Flex的設定檔flex-config.xml,在<web-service-proxy>的<whitelist>屬性中添加WebService的URL,我看了下檔案中的說明:
                For security, the whitelist is locked down by default.
                Uncomment the first two urls below to enable access to all URLs,
                or the last two urls to enable access to the local server,
                or add above the individual URLs you wish to access.
                <url>http://*</url>
                <url>https://*</url>
                <url>http://{localserver}/*</url>
                <url>https://{localserver}/*</url>
於是我就將http://*添加到了<url></url>中。
     結果再次運行還是說串連不到WebService。我又重新把代碼複製到Flex2.0裡,改了幾個文法變化的地方,結果Flex2.0就可以串連到WebService。搞不懂為什麼。
    星期六回到家裡我仔細的找了下原因,原來Flex的WebService組件裡有一個userProxy屬性,在1.5裡我把這個屬性設定為false就能串連到WebService了。這個屬性在FlexBuilder的智能感知裡是沒有的,真是害死我們這些初學者啊。
    我串連上了天氣預報的WebService可是它返回來的資料不是XML格式的,我還沒搞清楚怎麼用,所以這裡我做了一個串連RSS閱讀服務的程式,這個WebService通過所給的RSS串連返回解析出來的HTML代碼。
    這個Flex程式的代碼如下:
   

<? xml version="1.0" encoding="utf-8" ?>
< mx:Application  xmlns:mx ="http://www.macromedia.com/2003/mxml" >
     < mx:WebService  id ="RSSService"  useProxy ="false"
     wsdl ="http://www.webservicex.net/RssToHTML.asmx?WSDL"
     fault ="alert(event.fault.faultstring)"  showBusyCursor ="true" >
      < mx:operation  name ="GetHTML" >
          < mx:request >
             < RSSURL > {tiRSS.text} </ RSSURL >
         </ mx:request >
      </ mx:operation >
     </ mx:WebService >
     < mx:Panel  width ="500"  height ="500"  cornerRadius ="8"  panelBorderStyle ="roundCorners" >
         < mx:VBox  horizontalAlign ="center"  width ="100%" >
          < mx:HBox >
             < mx:Label  text ="RSS Url:"  width ="50"   />
             < mx:TextInput  id ="tiRSS"  width ="300"  toolTip ="在此輸入RSS串連地址"  text ="http://bg5sbk.cnblogs.com/Rss.aspx"   />
             < mx:Button  click ="RSSService.GetHTML.send()"  label ="Get"  width ="50"   />
          </ mx:HBox >
          < mx:TextArea  text ="{RSSService.GetHTML.result}"  width ="400"  height ="400"  cornerRadius ="10"   />
          </ mx:VBox >
     </ mx:Panel >
</ mx:Application >

產生的Flash:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.