有时你要连接的服务并非是SOAP风格的。其他常用的框架可以结合使用HTTP Get和Post方法来返回数据。使用<mx:HTTPService>标签可以让你访问这种类型的WEB服务。
使用HTTP Post和Get方法操作的WEB服务可以理解为REST服务。在很多情况下,使用HTTP Post方法。使用HTTP Web服务的一个明显的好处是你可以传递比使用SOAPWeb服务时更少的数据。
Adobe Flexx 数据访问组件使用远程过程调用(RPC)来与服务器环境交互,例如PHP,Adobe ColdFusion,和Microsoft ASP.NET,来为Flex程序提供数据,以及将数据传递给后台的数据源。
连接到一个HTTP Web服务
可以很容易的使用<mx:HTTPSevice>。<mx:HTTPService>有着类似<mx:WebService>和<mx:HTTPService>标签的属性,且具有falt和result时间供你监听和处理,如下所示:
<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>
url="http://search.yahooapis.com/WebSearchService/V1/webSearch"
method="GET"
makeObjectsBindable="true" result="httpServiceResult(event)"
fault="httpServiceFault(event)" showBusyCursor="true">
</mx:HTTPService>
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();
}
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();
}
转载于:https://blog.51cto.com/flexria/156699