| Flex 2 Developer's Guide > Data Access and Interconnectivity > Using RPC Components > Declaring an RPC component > Using a service without server-side configuration | |||
You can use RPC components to connect to HTTP services and web services without configuring Flex Data Services destinations. To do so, you set an HTTPService component's url property or a WebService component's wsdl property instead of setting the component's destination property.
When an RPC component's useProxy property is set to false, the default value, the component communicates directly with the RPC service based on the url or wsdl property value. If you are not using Flex Data Services, the useProxy property value must be false. Connecting to a service in this manner requires that at least one of the following is true:
When you set an HTTPService or WebService component's useProxy property to true and set the url or wsdl property and do not set the destination property, the component uses a default destination that is configured in the <proxy-service> section of the services-config.xml file or a file that it includes by reference, such as the proxy-config.xml file. This requires Flex Data Services, and the defaultHTTP or defaultHTTPS destination in the configuration file must contain a URL pattern that matches the value of your component's url or wsdl property, respectively. The defaultHTTPS destination is used when your url or wsdl property specifies an HTTPS URL.
The following examples show MXML tags for declaring HTTPService and WebService components that directly reference RPC services. The id property is required for calling the services and handling service results. In these examples, the useProxy property is not set in the tags; the components use the default useProxy value of false and contact the services directly, as is required when you are not using Flex Data Services.
...
<mx:HTTPService
id="yahoo_web_search"
url="http://api.search.yahoo.com/WebSearchService/V1/webSearch"/>
...
<mx:WebService
id="macr_news"
wsdl="http://ws.invesbot.com/companysearch.asmx?wsdl"/>
...
The following examples show ActionScript code for declaring HTTPService and WebService components with no corresponding server-side configuration. In these examples, the useProxy property is not set explicitly; the components use the default useProxy value of false and contact the services directly, as is required when you are not using Flex Data Services. You would place the code for declaring the components in ActionScript methods:
...
// Import required packages.
import mx.rpc.http.HTTPService;
import mx.rpc.soap.WebService;
...
// Declare an HTTPService component.
private var yahoo_web_search:mx.rpc.http.HTTPService = new HTTPService();
yahoo_web_search.url =
"http://api.search.yahoo.com/WebSearchService/V1/webSearch";
...
// Declare a WebService component.
private var macr_news:mx.rpc.soap.WebService = new WebService();
macr_news.wsdl =
"http://ws.invesbot.com/companysearch.asmx?wsdl";
...
|
NOTE |
|
You must use the Flex proxy, which is part of Flex Data Services, to ensure that HTTP status codes are returned correctly from HTTP services and web services. On web browsers, when a service returns any status code other than 200, Adobe Flash Player cannot read the body of the response. If the status code is 500 and the body contains a fault, there is no way to get to the fault. The proxy works around this issue by forcing the status code for faults to 200; the player passes the body of the response along with the fault intact. |
Flex 2
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flex/2/docs/00001128.html