`
阅读更多
Remote-procedure-call (RPC) services let your application interact with remote servers to provide data to your applications, or for your application to send data to a server.
Flex is designed to interact with several types of RPC services that provide access to local and remote server-side logic. For example, a Flex application can connect to a web service that uses the Simple Object Access Protocol (SOAP), a Java object residing on the same application server as Flex using AMF, or an HTTP URL that returns XML.
The MXML components that provide data access are called RPC components. MXML includes the following types of RPC components:
* WebService provides access to SOAP-based web services.
* HTTPService provides access to HTTP URLs that return data.
* RemoteObject provides access to Java objects using the AMF protocol (Adobe LiveCycle Data Services ES only).
The following example shows an application that calls a web service that provides weather information, and displays the current temperature for a given ZIP code. The application binds the ZIP code that a user enters in a  control to a web service input parameter. It binds the current temperature value contained in the web service result to a TextArea control.
    Remote-procedure-call (RPC)服务给你的程序提供了和远程服务器进行交互的能力,或者让你的程序可以向服务器发送数据。
    Flex设计了多种RPC服务的形式,可以让你的程序接入本地或远程服务器端。一个Flex应用程序可以使用“简单对象接入协议”(SOAP),一个和当前Flex程序属于同一个工程的Java对象可一通过AMF,或者HTTP URL来返回一个XML。
    提供了数据接入的MXML组件我们称之为RPC组件。MXML包含了一下几种类型的RPC组件:
* WebService 访问基于SOAP的服务器。
* HTTPService 访问 HTTP URL 从而得到数据。
* RemoteObject 使用AMF协议调用Java 对象(仅限于Adobe LiveCycle Data Services ES)。
    下面的例子展示了一个应用程序,该程序根据给定的邮政编码来请求服务器端提供的天气信息,并显示出来。程序获得用户在TextInput控件输入的邮政编码,然后作为向服务器进行请求的参数。它将返回的温度值绑定到TextArea控件上。
<?xml version="1.0"?>
<!-- mxml/RPCExample.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <!-- Define the web service connection
        (the specified WSDL URL is not functional). -->
    <mx:WebService id="WeatherService"       
        wsdl="http:/example.com/ws/WeatherService?wsdl" 
        useProxy="false">
        <!-- Bind the value of the ZIP code entered in the TextInput control
            to the ZipCode parameter of the GetWeather operation. -->
        <mx:operation name="GetWeather">
            <mx:request>
                <ZipCode>{zip.text}</ZipCode>
            </mx:request>
        </mx:operation>
    </mx:WebService>
    
    <mx:Panel title="My Application" paddingTop="10" paddingBottom="10"
        paddingLeft="10" paddingRight="10" >
        <!-- Provide a ZIP code in a TextInput control. -->
        <mx:TextInput id="zip" width="200" text="Zipcode please?"/>
        <!-- Call the web service operation with a Button click. -->
        <mx:Button width="60" label="Get Weather"
            click="WeatherService.GetWeather.send();"/>
        <!-- Display the location for the specified ZIP code. -->
        <mx:Label text="Location:"/>
        <mx:TextArea text="{WeatherService.GetWeather.lastResult.Location}"/>
        <!-- Display the current temperature for the specified ZIP code. -->
        <mx:Label text="Temperature:"/>
        <mx:TextArea
            text="{WeatherService.GetWeather.lastResult.CurrentTemp}"/>
    </mx:Panel>
</mx:Application>

下图展示了运行效果
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics