访问服务器端数据
有時你要連接的服務(wù)并非是SOAP風格的。其他常用的框架可以結(jié)合使用HTTP Get和Post方法來返回數(shù)據(jù)。使用<mx:HTTPService>標簽可以讓你訪問這種類型的WEB服務(wù)。
使用HTTP Post和Get方法操作的WEB服務(wù)可以理解為REST服務(wù)。在很多情況下,使用HTTP Post方法。使用HTTP Web服務(wù)的一個明顯的好處是你可以傳遞比使用SOAPWeb服務(wù)時更少的數(shù)據(jù)。
Adobe Flexx 數(shù)據(jù)訪問組件使用遠程過程調(diào)用(RPC)來與服務(wù)器環(huán)境交互,例如PHP,Adobe ColdFusion,和Microsoft ASP.NET,來為Flex程序提供數(shù)據(jù),以及將數(shù)據(jù)傳遞給后臺的數(shù)據(jù)源。 連接到一個HTTP Web服務(wù)可以很容易的使用<mx:HTTPSevice>。<mx:HTTPService>有著類似<mx:WebService>和<mx:HTTPService>標簽的屬性,且具有falt和result時間供你監(jiān)聽和處理,如下所示:
<mx:HTTPService id="yahooHTTPService"
????????url="http://search.yahooapis.com/WebSearchService/V1/webSearch"
????????method="GET"
????????makeObjectsBindable="true" result="httpServiceResult(event)"
????????fault="httpServiceFault(event)" showBusyCursor="true">
</mx:HTTPService>和使用<mx:WebService>標簽時不同,你不需要定義操作。所有要發(fā)送到服務(wù)器進行處理的變量將作為鍵值對傳到url屬性定義的URL。這個標簽的行為與HTML表單的get或post的行為相同。要向服務(wù)器傳遞數(shù)據(jù),你只需要傳遞攜帶著那些變量的對象。Flex會將那些變量封裝進正確的格式。下面的代碼展示了對上面<mx:HTTPService>標記進行處理的ActionScript代碼:public function httpServiceResult(e:ResultEvent):void {
??????Alert.show("received a result");
????}
????public function httpServiceFault(e:FaultEvent):void {
??????Alert.show("received a Fault");
????}
????public function sendHttpRequest():void {
??????var requestObj:Object = new Object();
??????requestObj.appid = new String("YahooDemo");
??????requestObj.query = new String("persimmon");
??????requestObj.results = new int(2);
??????yahooHTTPService. request = requestObj;
??????httpAsyncToken = yahooHTTPService.send();
????}
使用HTTP Post和Get方法操作的WEB服務(wù)可以理解為REST服務(wù)。在很多情況下,使用HTTP Post方法。使用HTTP Web服務(wù)的一個明顯的好處是你可以傳遞比使用SOAPWeb服務(wù)時更少的數(shù)據(jù)。
Adobe Flexx 數(shù)據(jù)訪問組件使用遠程過程調(diào)用(RPC)來與服務(wù)器環(huán)境交互,例如PHP,Adobe ColdFusion,和Microsoft ASP.NET,來為Flex程序提供數(shù)據(jù),以及將數(shù)據(jù)傳遞給后臺的數(shù)據(jù)源。 連接到一個HTTP Web服務(wù)可以很容易的使用<mx:HTTPSevice>。<mx:HTTPService>有著類似<mx:WebService>和<mx:HTTPService>標簽的屬性,且具有falt和result時間供你監(jiān)聽和處理,如下所示:
<mx:HTTPService id="yahooHTTPService"
????????url="http://search.yahooapis.com/WebSearchService/V1/webSearch"
????????method="GET"
????????makeObjectsBindable="true" result="httpServiceResult(event)"
????????fault="httpServiceFault(event)" showBusyCursor="true">
</mx:HTTPService>和使用<mx:WebService>標簽時不同,你不需要定義操作。所有要發(fā)送到服務(wù)器進行處理的變量將作為鍵值對傳到url屬性定義的URL。這個標簽的行為與HTML表單的get或post的行為相同。要向服務(wù)器傳遞數(shù)據(jù),你只需要傳遞攜帶著那些變量的對象。Flex會將那些變量封裝進正確的格式。下面的代碼展示了對上面<mx:HTTPService>標記進行處理的ActionScript代碼:public function httpServiceResult(e:ResultEvent):void {
??????Alert.show("received a result");
????}
????public function httpServiceFault(e:FaultEvent):void {
??????Alert.show("received a Fault");
????}
????public function sendHttpRequest():void {
??????var requestObj:Object = new Object();
??????requestObj.appid = new String("YahooDemo");
??????requestObj.query = new String("persimmon");
??????requestObj.results = new int(2);
??????yahooHTTPService. request = requestObj;
??????httpAsyncToken = yahooHTTPService.send();
????}
轉(zhuǎn)載于:https://blog.51cto.com/flexria/156699
總結(jié)
- 上一篇: SI9000常用共面阻抗模型的解释
- 下一篇: 编写高质量代码改善C#程序的157个建议