Flex provides <mx:WebService>, <mx:HTTPService> and <mx:RemoteObject> tags for direct access to remote data, which is used with a variety of different language It is easier to communicate the remote server data sources (such as WebService) provided by the environment development.
This article takes. NET platform under the C # language development WebService as a remote webservice, the detailed introduction of flex and. NET Data communication knowledge points webservice, including connection WebService, Remote Call WebService method, The WebService method is used to transfer parameters and other related knowledge points. The use of the three tags is basically the same, and here the <mx:WebService> tag as an example to introduce.
First look at the following code block:
1 <mx:WebService id="dataService"
2 wsdl="http://localhost/FlashFlex/DataWebService.asmx?wsdl"
3 useProxy="false">
4 <mx:operation name="HelloWorld" result="onSuccess(event)" fault="onFault(event)"/>
5 <mx:operation name="GetBook" fault="onFault(event)" result="onObjectSuccess(event) "/>
6 </mx:WebService>
The WSDL property specifies the WSDL address of the WebService to be accessed, which defines two action labels (<mx:operation>), respectively, corresponding to the WebMethod method defined in WebService. The result property tag accesses the successful handler function of the WebService method; fault, instead, specifies the handler function that accesses the failure. The above two <mx:operation> WebMethod methods corresponding to WebService are as follows:
1 /// <summary>
2 /// 返回字符串
3 /// </summary>
4 /// <returns></returns>
5 [WebMethod]
6 public string HelloWorld ()
7 {
8 return "Hello World";
9 }
10
11 /// <summary>
12 /// 返 回一个简单对象
13 /// </summary>
14 /// <returns></returns>
15 [WebMethod]
16 public Book GetBook()
17 {
18 return new Book
19 {
20 Id = 1,
21 Name = "三国演义",
22 Author = "罗贯中",
23 Price = 100
24 };
25 }