


Flex and .NET interoperability (3): Data access based on WebService (2)
In the previous article "Flex and .NET Interoperability (2): Data Access Based on WebService (1)", we introduced access to Webservice through the
Using the WebService class to access WebService actually means expressing the attributes of the
1 internalfunctiononClick():void
2{
3varservice:WebService=newWebService();
4service.loadWSDL("http: //localhost:1146/FlashFlexService.asmx?wsdl");
5service.addEventListener(ResultEvent.RESULT,onResult);
6service.addEventListener(FaultEvent.FAULT,onFault);
7service.GetBook();
8}
Simply call the remote WebService directly through the loadWSDL() method of the class object, dynamically specify the relevant processing function for the class object, and then call the remote WebService method just like the label.
1 internalfunctiononResult(evt:ResultEvent):void
2{
3Alert.show(evt.result.Id);
4}
5
6internalfunctiononFault(evt:FaultEvent):void
7 {
8Alert.show(evt.fault.faultDetail.toString());
9}
The above completes the use of the WebService class to programmatically access the remote WebService method call.
Let’s take a look at the responsible types such as DataTable returned by WebService, and how to parse them on the Flex client. First define the WebService method as follows:
1[WebMethod(Description="This method will return data of type DataTable")]
2publicDataTableGetDataTable()
3{
4DataTabledt=newDataTable("Books") ;
5dt.Columns.Add("Id",typeof(int));
6dt.Columns.Add("Name",typeof(string));
7dt.Columns.Add("Author",typeof(string) );
8dt.Columns.Add("Price",typeof(double));
9
10DataRowdr=dt.NewRow();
11dr["Id"]=1;
12dr["Name"]=" Flex Game Development";
13dr["Author"]="Zhang San";
14dr["Price"]=54.85;
15dt.Rows.Add(dr);
16
17dr=dt.NewRow();
18dr["Id"]=2;
19dr["Name"]=""Flash Game Development"";
20dr["Author"]="李思";
21dr["Price"]=65.50;
22dt.Rows.Add(dr);
23
24returndt;
25}
It can also be accessed through WebService on the Flex client. The following is accessed using the
1
3
4
5
The WebService is provided and the client is connected After removing WebService, now all we have to do is call the remote method provided by WebService. As follows:
1
2
4
5
6
7
8
9
10
11
12
13
14
Bind the data source of the DataGrid component through the dataProvider property of DataGrid, in addition to directly through " {}"In addition to the help of binding expressions, we can also specify the data source for the DataGrid in the handler function that successfully calls the remote method. See the commented code part in the above code. {this.myService.GetDataTable.lastResult.Tables.Books.Rows} means that all rows of the result (DataTable) returned by the remote WebService method GetDataTable() are used as data sources to bind to the DataGrid component, where Books is the name of the data source DataTable. ,
DataSet, DataTable have a big gap in performance compared to generic collections, and the complex serialization and deserialization processes are also very responsible. I have always preferred generics since .net 2.0 launched them. Use generics to pass big data. OK, now I will introduce how to process the generic collection data returned by the WebService method in Flex. We have the following WebService method definition:
1 [WebMethod(Description="This method returns a generic collection")]
2publicList
3{
4returnnewList
5{
6newBook
7{
8Id=1,
9Name=""Flex Game Development"",
10Author="Zhang San",
11Price=54.85
12},
13newBook
14{
15Id=1,
16Name=""Flash Game Development"",
17Author="李思",
18Price=65.50
19}
20};
21}
Compared with DataSet and DataTable types, I personally use List<> to return data I think it's easier to handle.
This is the data form returned in the form of generic combination (List<>). Compared with the return result of DataTable, it is more concise and clear. Having said that, how do we get this return value and process this value in Flex? In fact, it has been clearly shown here how we can handle it. If you look carefully at the picture above, you will find "ArrayOfBook"? ? ? ? What is this? Could it be that the client can get this return value in the form of an array. In order to further understand the details of this, we need to go deep inside to understand the specific structure of the return value. Through the debugging environment of Flex Builder, we can get the following information:
Do you see it clearly? There are two objects under the lastResult structure set of the BookList method. Clicking on the node shows that it is the two Book objects we returned through List
1
2
3
4
5< mx:DataGridColumnheaderText="Book title" dataField="Name"/>
6
7
8
9
10
11
12
13
That’s it for introducing the data access of WebService. Due to my limited personal ability, I hope everyone can correct me if there are any deficiencies in the article. If you have any good suggestions, you can also put them forward, let everyone discuss, learn and make progress together! !

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This article explains how to create newline characters in C using the \n escape sequence within printf and puts functions. It details the functionality and provides code examples demonstrating its use for line breaks in output.

This article explores the challenges of NULL pointer dereferences in C. It argues that the problem isn't NULL itself, but its misuse. The article details best practices for preventing dereferences, including pre-dereference checks, pointer initiali

This article guides beginners on choosing a C compiler. It argues that GCC, due to its ease of use, wide availability, and extensive resources, is best for beginners. However, it also compares GCC, Clang, MSVC, and TCC, highlighting their differenc

This article emphasizes the continued importance of NULL in modern C programming. Despite advancements, NULL remains crucial for explicit pointer management, preventing segmentation faults by marking the absence of a valid memory address. Best prac

This article reviews online C compilers for beginners, focusing on ease of use and debugging capabilities. OnlineGDB and Repl.it are highlighted for their user-friendly interfaces and helpful debugging tools. Other options like Programiz and Compil

This article discusses efficient code copying in C IDEs. It emphasizes that copying is an IDE function, not a compiler feature, and details strategies for improved efficiency, including using IDE selection tools, code folding, search/replace, templa

This article compares online C programming platforms, highlighting differences in features like debugging tools, IDE functionality, standard compliance, and memory/execution limits. It argues that the "best" platform depends on user needs,

This tutorial guides users through installing C compilers on Windows, macOS, and Linux. It details installation for popular compilers (MinGW, Visual Studio, Xcode, GCC), explains environment variable configuration, and offers troubleshooting steps
