Flex and. Net interoperability (6): fluorinefx, a tool for flex and. Net collaborative development

Source: Internet
Author: User
Tags cdata

Before this seriesArticleDescribes the knowledge points of communication between flex and the. NET Server through WebService, httpservice, urlloader, fielreference, and other components or classes. It is very convenient and simple to communicate with the server through these methods, but its disadvantage is that the data volume is small, if we want to transmit a large amount of data or implement serialized transmission of different objects, they will not meet our needs and we need to find another communication protocol, another efficient transmission protocol to replace the SOAP protocol is the AMF (ActionScript Message format) protocol.

Fluorinefx, an open-source project, is an AMF communication gateway dedicated to. NET platform and flex communication. We can use fluorinefx to conveniently communicate with. net.

Fluorinefx officially provides download and online documentation for the installation package, which can help us effectively develop with fluorinefx.

Fluroinefx Official Website: http://www.fluorinefx.com/

Fluroinefx: http://www.fluorinefx.com/download.html

Fluroinefx online documentation: http://www.fluorinefx.com/docs/fluorine/index.html

OK. Let's take a look at the. NET and flex configurations for fluroinefx communication. Select the following development environment:

. Net: Microsoft Visual Studio 2008 +. NET Framework 3.5

Flex: Adobe Flex builder CS3 + flex SDK 3.2

Fluroinefx: fluorinefx v1.0.0.15 (click to download)

 

1... NET Server Development

Use Microsoft Visual Studio 2008 to create a solution and add the fluroinefx server library, as shown in:

After the fluorinefx service library is successfully added, the Project template automatically creates a sample class and an echo method for us, as shown below:

1 Namespace Flexdotnet. servicelibrary
2 {
3 ///   <Summary>
4 /// Fluorine Sample Service.
5 ///   </Summary>
6 [Remotingservice ( " Fluorine Sample Service " )]
7 Public   Class Sample
8 {
9 Public Sample ()
10 {
11 }
12
13 Public   String Echo ( String Text)
14 {
15 Return   " Gateway ECHO: "   + Text;
16 }
17 }
18 }

 

Add the fluorinefx website to the solution. After the solution is successfully added, the website will automatically reference the DLL of the fluorinefx service library. For example:

Here we can test whether fluorinefx's. NET Server is successfully created. You can view the console. aspx in the fluroinefx website in the browser or set the website to a startup project and console. aspx to the start page to run the website,ProgramThen it runs to the fluorinefx console. Expand the services node of the project on the left and you will see the class and method created by the template above. Click the method node on the right to perform a simple test, as shown in:

OK. Now the. NET Server is developed. Here, we need to remember the following points. In the next flex development, we need to configure these parameters.

Fluorinefx. Net website directory: F: \ demo \ flexdotnet \ Web

Fluorinefx's. Net website virtual directory:/Web

Fluorinefx. Net website URL: http: // localhost: 2836/Web

URL for receiving flex client requests: http: // localhost: 2836/web/gateway. aspx

With the above configurations, it is easy to configure Flex. First, create a flex project and point the project path to the root path of the fluorinefx website created in the previous step:

For example, Set application type to Web application and application server type:ASP. NETAnd then "Next ". Go to the next project creation Wizard Page and set the server :"Use Internet Information Services (IIS)", The Web application root also points to the root path of the fluorinefx website, and the Web appliation URL is set to the path we obtained above. For details, see:

After the configuration is complete, click "Validate configuration" for configuration verification. If the verification result is: the Web application root and the URL are valid. the configuration is correct. You can click Next to create a project.

After the flex project is created, you can use fluorinefx to communicate with. NET through some corresponding configurations. On the Development Project property settings panel, set the flex compiler as shown in (-services configuration can also be set to a relative path ):

Set the flex server to the following configuration. You can click "Validate location" to verify the correctness of the Configuration:

Finally, set the output path to complete the configuration of the Flex end:

 

Now, all the Flex-side configurations are completed. The following uses the fluorinefx library template as an example to test whether the environment can pass through, and <mx: remoteobject> tag to access remote objects, as shown in the following figure:

1 < MX: remoteobject ID = " Service " Destination = " Fluorine "
2 Source = " Flexdotnet. servicelibrary. Sample " >
3 < MX: Method Name = " Echo " Result = " Onresult (Event) " >
4 </ MX: Method >
5 </ MX: remoteobject >

 

Note that destination needs to be set to be the same as the destination ID in the remoting-config.xml, and source is configured as the full path of the remote object (namespace + class), through the <mx: method> label: configure the method under the remote object and set the result processing function after the method is successfully called. Then you can call the remote method by ID.

1 < MX: script >
2 <! [CDATA [
3 Import MX. rpc. Events. resultevent;
4 Internal Function Onclick (): Void
5 {
6 Service. Echo (txtinput. Text );
7 }
8
9 Internal Function Onresult (EVT: resultevent ): Void
10 {
11 Txtresult. Text = EVT. Result. tostring ();
12 }
13 ] >
14 < / MX: SCRIPT>

 

Below is the complete flex client mxmlCodeDefinition:

Complete sample code
1 <? XML version = "1.0" encoding = "UTF-8" ?>
2 < MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml" Layout = "Absolute" >
3 < MX: remoteobject ID = "Service" Destination = "FLUORINE"
4 Source = "Flexdotnet. servicelibrary. sample" >
5 < MX: Method Name = "Echo" Result = "Onresult (event )" >
6 </ MX: Method >
7 </ MX: remoteobject >
8
9 < MX: script >
10 <! [CDATA [
11 Import MX. rpc. Events. resultevent;
12 Internal function onclick (): void
13 {
14 Service. Echo (txtinput. Text );
15 }
16
17 Internal function onresult (EVT: resultevent): void
18 {
19 Txtresult. Text = EVT. Result. tostring ();
20 }
21 ] >
22 </ MX: script >
23
24 < MX: Panel X = "53" Y = "52" Width = "250" Height = "200" Layout = "Absolute" Title = "Test fluorinefx" Fontsize = "12" >
25 < MX: textinput X = "35" Y = "21" ID = "Txtinput" />
26 < MX: button X = "35" Y = "63" Label = "Confirm" Fontweight = "Normal" Click = "Onclick ()" />
27 < MX: Label X = "35" Y = "95" Text = "Result :" />
28 < MX: textinput X = "35" Y = "123" Width = "160" ID = "Txtresult" />
29 </ MX: Panel >
30 </ MX: Application >
31

 

Example:

 

Author: beniao

Article Source: http://beniao.cnblogs.com/or http://www.cnblogs.com/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.