search
HomeBackend DevelopmentC#.Net TutorialFlex and .NET interoperability (2): Data access based on WebService (1)

Flex provides , and tags to directly access remote data, which is used to develop remote server data sources provided by various different language environments (such as WebService) makes data interactive communication easier.

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 tag as an example.

First take a look at the following code block:

12wsdl="http://localhost/FlashFlex/DataWebService.asmx?wsdl"
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 ( ), respectively corresponding to the WebMethod method defined in WebService. The result attribute marks the processing function after successful access to the WebService method; fault, on the contrary, specifies the processing function for access failure. The above two correspond to the WebMethod methods of WebService as follows:

1///


2///return string
3///
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) 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<script><br>23importmx.controls.Alert;<br>4importmx.rpc.events.FaultEvent;<br>5importmx.rpc.events.ResultEvent;<br>6<br>7/**<br>8* Initiate a request to WebService - call the HelloWorld method, dataService is the id of <webservice><br>9**/<br>10internalfunctiononRequest():void<br>11{ <br>12dataService.HelloWorld();<br>13}<br>14<br>15/**<br>16*Request result returned after successful processing<br>17**/<br>18internalfunctiononSuccess(evt:ResultEvent):void<br>19{<br>20Alert.show(evt.result.toString());<br>21 }<br>22<br>23<br>24/**<br>25*Handling function for request failure<br>26**/<br>27internalfunctiononFault(evt:FaultEvent):void<br>28{<br>29Alert.show("Failed to access WebService!");<br>30}<br>31]]><br> 32</webservice></script>

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 under the tag to execute this method, as follows :

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 to pass parameters. Here you only need to know that the parameter configuration in has the same name as the WebMethod method parameter provided by WebService.

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}


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to add next-level C compilerHow to add next-level C compilerMar 03, 2025 pm 05:44 PM

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.

What are the alternatives to NULL in C languageWhat are the alternatives to NULL in C languageMar 03, 2025 pm 05:37 PM

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

Which C language compiler is better?Which C language compiler is better?Mar 03, 2025 pm 05:39 PM

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

Is NULL still important in modern programming in C language?Is NULL still important in modern programming in C language?Mar 03, 2025 pm 05:35 PM

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

What are the web versions of C language compilers?What are the web versions of C language compilers?Mar 03, 2025 pm 05:42 PM

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

Method of copying code by C language compilerMethod of copying code by C language compilerMar 03, 2025 pm 05:43 PM

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

C language online programming website C language compiler official website summaryC language online programming website C language compiler official website summaryMar 03, 2025 pm 05:41 PM

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,

C language compiler installation tutorial (computer version)C language compiler installation tutorial (computer version)Mar 03, 2025 pm 05:41 PM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.