有时你要链接的服务并不是是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
>
和使用<mx:WebService>标签时不一样,你不须要定义操做。全部要发送到服务器进行处理的变量将做为键值对传到url属性定义的URL。这个标签的行为与HTML表单的get或post的行为相同。要向服务器传递数据,你只须要传递携带着那些变量的对象。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(); }