


Flex and .NET interoperability (2): Data access based on WebService (1)
Flex provides
This article uses WebService developed in C# language under the .NET platform as a remote data source to introduce in detail the data communication knowledge points between Flex and .NET's WebService; including connecting to WebService and remotely calling WebService methods , passing parameters and other related knowledge points to the WebService method. The usage of the three tags is basically the same. Here we take the
First take a look at the following code block:
1
3useProxy=" false">
4
5
6
wsdl attribute can be specified to the wsdl address of the WebService to be accessed, which defines two operation tags (
1///
2///return string
3///< /summary>
4///
5[WebMethod]
6publicstringHelloWorld()
7{
8return"HelloWorld";
9}
10
11///
12///Return a simple object
13///
14///
15[WebMethod]
16publicBookGetBook()
17{
18returnnewBook
19{
20Id=1,
21Name="Romance of the Three Kingdoms",
22Author="Luo Guanzhong",
23Price=100
24};
25}
The above is the WebService method definition and passed in the Flex client (mxml)< mx:WebService> tag to access the complete process of WebService. Let’s take a look at how to call the methods defined by WebService on the Flex client:
1
2< ![CDATA[
3importmx.controls.Alert;
4importmx.rpc.events.FaultEvent;
5importmx.rpc.events.ResultEvent;
6
7/**
8* Initiate a request to WebService - call the HelloWorld method, dataService is the id of
9**/
10internalfunctiononRequest():void
11{
12dataService.HelloWorld();
13}
14
15/**
16*Request result returned after successful processing
17**/
18internalfunctiononSuccess(evt:ResultEvent):void
19{
20Alert.show(evt.result.toString());
21 }
22
23
24/**
25*Handling function for request failure
26**/
27internalfunctiononFault(evt:FaultEvent):void
28{
29Alert.show("Failed to access WebService!");
30}
31]]>
32
Through the above call, you can complete an interaction between Flex and .NET WebService. Of course, we can also pass parameters when calling WebService on the Flash/Flex client. The following WebMethod definition of WebService is as follows:
1///
2///will be passed in Convert the parameters to uppercase characters and return
3///
4///
5///
6[WebMethod]
7publicstringConvertToUpper(stringvalue)
8{
9returnvalue.ToUpper();
10}
You can access it by configuring
1
1 /* *
2*Initiate a request to WebService
3**/
4internalfunctiononRequest():void
5{
6//dataService.HelloWorld();
7dataService.ConvertToUpper("abcdefg");
8}
In addition, we can also pass
Go back to the front and take a look at the method definition of WebService. One of the methods, GetBook, returns a Book object. If it is the returned object, how do we get the value of this object on the Flex client? For details, see the following code example:
1internalfunctiononObject():void
2{
3dataService.GetBook();
4}
5
6internalfunctiononObjectSuccess(evt:ResultEvent):void
7{
8 //Get the return value directly through the event's result attribute, and then access the attribute directly to OK
9Alert.show(evt.result.Name);
10}
11
12/**
13*Handling function for request failure
14**/
15internalfunctiononFault(evt: FaultEvent):void
16{
17Alert.show("Access to WebService failed!");
18}

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 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 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 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 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 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 troubleshoots missing output windows in C program compilation. It examines causes like failing to run the executable, program errors, incorrect compiler settings, background processes, and rapid program termination. Solutions involve ch
