Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of data access based on WebService in Flex and .NET Interoperability

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail the example analysis of WebService-based data access in Flex and .NET interoperability. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Interoperability between Flex and .NET: data access based on WebService

Flex provides, and tags to access remote data directly, which makes it easier to communicate with remote server data sources (such as WebService) provided by different language development environments.

This paper takes WebService developed by C # language under .NET platform as the remote data source, and introduces in detail the knowledge points of data communication between Flex and WebService in .NET, including connecting WebService, remotely calling WebService method, passing parameters to WebService method and so on. The use of the three tags is basically the same, here to label as an example to introduce.

Connect WebService

First, take a look at the following code block:

1 4 5 6

The wsdl attribute can be specified to the wsdl address of the WebService to be accessed, where two action tags () are defined, corresponding to the WebMethod method defined in WebService.

The result attribute marks the handler after a successful access to the WebService method; fault, by contrast, specifies the handler that failed to access. The above two WebMethod methods corresponding to WebService are as follows:

1 18returnnewBook / 2 16publicBookGetBook / return string 3 18returnnewBook / 4 20Id=1 / 5 [8return] 6publicstringHelloWorld () 7 {8return "HelloWorld"; 9} 10 11 18returnnewBook / 12 / return a simple object 13 18returnnewBook / 15 [20Id=1] 16publicBookGetBook () 17 {18returnnewBook 19 {20Id=1, 21Name = Romance of the three Kingdoms, 22 Author= "Luo Guanzhong", 23Price=100 24}; 25}

Call the method defined by WebService

The complete process, let's take a look at how the client in Flex can call the method defined by WebService:

12 id 9 requests / 10internalfunctiononRequest (): void 11 {12dataService.HelloWorld (); 13} 14 15 CPUs * 16 * the request was successfully processed and the result returned 17 cycles / 18internalfunctiononSuccess (evt:ResultEvent): void 19 {20Alert.show (evt.result.toString ()); 21} 22 23 24 Universe * 25 * the request failed handler function 26 requests / 27internalfunctiononFault (evt:FaultEvent): void 28 {29Alert.show ("access to WebService failed!") 30} 31]] > 32

Pass parameters to the WebService method

Through the above call, you can complete an interaction between Flex and .NET Web Service. Of course, we can also pass parameters when we call WebService on the client side of Flash/Flex, as shown in the WebMethod definition of WebService:

1 WebMethod / 2 7publicstringConvertToUpper / convert the passed parameters to uppercase characters return 3 / 4 / 5 / 6 [WebMethod] 7publicstringConvertToUpper (stringvalue) 8 {9returnvalue.ToUpper (); 10}

◆ can be accessed by configuring this method under the tag, as follows:

1. 7dataService.ConvertToUpper ("abcdefg"); 8}; void 5 {6//dataService.HelloWorld (); 7dataService.ConvertToUpper ("abcdefg"); 8}

In addition, we can also pass parameters through, here we just need to know that the parameter configuration in OK has the same name as the WebMethod method parameter provided by WebService.

Going back to the method definition of WebService, one of the methods GetBook is a returned Book object. If it is a returned object, how can we get the value of this object on the client side of Flex? For more information, see the following code example:

1internalfunctiononObject (): void 2 {3dataService.GetBook (); 4} 5 6internalfunctiononObjectSuccess (evt:ResultEvent): void 7 {8 17Alert.show / get the return value directly through the result attribute of the event, and then access the attribute directly to OK 9Alert.show (evt.result.Name); 10} 11 12 Universe * 13 * the handler function for the failed request: void 16 {17Alert.show ("access to WebService failed!") 18} this completes the call from the WebService on the server side to the client side. This is the end of the article on "sample Analysis of WebService-based data access in Flex and .NET Interoperability". I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report