Use weborb to implement the remoting of the Flex +. Net background

Source: Internet
Author: User
The simplest way to implement flex communication with the backend is through httpservic or WebService. However, both methods are based on text transmission, resulting in low transmission efficiency,
Using remoteobject, the transmitted content adopts the binary encoding in amf3 format, which is highly efficient and can realize remote object calling, code readability, and development efficiency.

Weborb is a solution officially recommended by Adobe to implement flex and. Net backend remoteobject. Currently, weborb is free of charge.

Principles of weborb:
1. on the server side, weborb uses. net httphandle mechanism. net program to display the ISAPI function mechanism in IIS. In my understanding, it is actually a distribution mechanism preprocessing mechanism. Similar functions include httpmodule. For example, you can use the httpmodule mechanism to reload the oninit method to implement the content that you do not need to change after it is initialized when the website system is accessed for the first time.

For example, to use weborb, add the following configuration in the web. config file:
<Httphandlers>
<Add verb = "*" Path = "weborb. aspx" type = "weborb. orbhttphandler"/>
<Add verb = "*" Path = "codegen. aspx" type = "weborb. Management. codegen. codegeneratorhttphandler"/>
</Httphandlers>
After callback processing, all requests named weborb. aspx are handled by the weborb. orbhttphandler class. Similarly, all requests on the codegen. ASPX page are handled by weborb. Management. codegen. codegeneratorhttphandler.

In weborb. in the orbhttphandler class, the content of the HTTP request is first parsed, decoded according to the flex amf3 binary format, and then passed according to the decoded information. net reflection mechanism to convert remote called objects.. Net object, and call the method specified by the client, then generate the corresponding result set, encode it into amf3 format, and return it to the customer's

2. on the client side, flex converts the destination specified during the remoteobect call to the corresponding URL call based on the services-config.xml configuration specified during compilation, and generates a corresponding HTTP request during the call, convert the classes and methods to be called into HTTP request content by protocol.

Weborb method:
. Net version:. NET 2.0 vs2005 Development Environment
Flex 3.0
Eclipse flex Builder
1. Download and install weborb
2. Create an Asp.net project flat
Copy the files in the weborb project directory (I installed them in: C: \ Inetpub \ wwwroot \ weborb30 ):
Copy weborb. config to the root directory
Diagnostics. aspx copy to the root directory
Copy weborb. DLL to the app_webreferences directory
3. Reference weborb. DLL to the flat Project
4. Modify the Web. config file of the flat project and add the following Configuration:
<Httphandlers>
<Add verb = "*" Path = "weborb. aspx" type = "weborb. orbhttphandler"/>
<Add verb = "*" Path = "codegen. aspx" type = "weborb. Management. codegen. codegeneratorhttphandler"/>
</Httphandlers>
5. copy all files under the WEB-INF directory to the flat project directory, can be arbitrarily specified, but the flex project must reference this directory, I copy to: e: \ wwwroot \ flexdatacenter \ WEB-INF \ flex
6. Create a CS file and add the following code: using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

/** // <Summary>
/// Summary of computeservice
/// </Summary>
Public class computeservice
{
Public computeservice ()
{
//
// Todo: add the constructor logic here
//

}

Public int compute (INT arg1, int arg2)
{
Return arg1 + arg2;
}
}

The compute method is used to calculate the sum of two parameters.

7. Create a flex project hellonet in eclipse.
8. Modify the compilation attribute of the hellonet project:
-Locale en_us-Services E: \ wwwroot \ flexdatacenter \ WEB-INF \ flex \ services-config.xml

It is mainly necessary to set-services parameters and set the read path of the services configuration file so that the SWF file maps the corresponding AMF channel to the corresponding URL when using remoteobject. This is very important!
The default Channel configuration is as follows:
<Channel-definition id = "My-AMF" class = "MX. messaging. channels. amfchannel">
<Endpoint uri = "weborb. aspx" class = "flex. messaging. endpoints. amfendpoint"/>
<Properties>
<Polling-enabled> false </polling-enabled>
</Properties>
</Channel-definition>
This configuration specifies that all remote requests with the ID my-AMF are mapped to the weborb. aspx of the current site and then processed by the httphandle handler of weborb. aspx.

9. Modify the build path and debug of the hellonet project, run path: e: \ wwwroot \ flexdatacenter \ Flex (this is the directory of the flat site)

Add the code to the flex application file: <? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "horizontal"
Xmlns = "http://www.degrafa.com/2007"
>

<Mx: SCRIPT>
<! [CDATA [
Import MX. rpc. Events. faultevent;
Import MX. Controls. Alert;
Import MX. rpc. Events. resultevent;
Import MX. Collections. arraycollection;
Import MX. rpc. Events. resultevent;
Private function getcomputerinfohandler (Event: resultevent): void {
Alert. Show (event. Result. tolocalestring ());
}

Private function getfaulthandler (Event: faultevent): void {
Alert. Show ("fault ");
}
]>
</MX: SCRIPT>

<Mx: button label = "Test Remote" Click = "compinfo. Compute (1, 4);">

</MX: button>
<Mx: remoteobject id = "compinfo" Destination = "genericdestination"
Source = "computeservice"
Showbusycursor = "true">
<Mx: method name = "compute" result = "getcomputerinfohandler (event)" fault = "getfaulthandler (event);"/>
</MX: remoteobject>

</MX: Application>

Note: the destination of the remoteobject object indicates the background to be called, all defined in the remoting-config.xml configuration file:
<Destination ID = "genericdestination">
<Properties>
<Source> * </source>
</Properties>
</Destination>
Resolved by. NET Server

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.