Use fluorinefx to transmit the datatable from. Net to flash

Source: Internet
Author: User

Fluorinefx comes with good examples, which is a little less concise. The followingCodeIt is basically the lite version (Environment vs2010)
1. Create a web application, and then add fluorinefx and fluorinefx. servicebrowser references.

These twoProgramThe default position of the set is:

C: \ Program Files (x86) \ fluorinefx \ bin \ net \ 3.5 \ fluorinefx. dll
C: \ Program Files (x86) \ fluorinefx \ bin \ net \ 3.5 \ fluorinefx. servicebrowser. dll

2. Add a dataservice. CS class and write the. NET Server code.

Using system. data; using fluorinefx; namespace datatabledemo {[remotingservice] public class dataservice {[datatabletype ("whatever you want")] public object getcountries (string capital) {datatable TBL = new datatable (); TBL. columns. add ("ID", typeof (system. int32); TBL. columns. add ("country", typeof (system. string); TBL. columns. add ("capital", typeof (system. string); TBL. rows. add (1, "Andorra", "Andorra"); TBL. rows. add (2, "United Arab", "Abu Dhabi"); TBL. rows. add (3, "Beijing", "China"); If (capital. length> 0) {datatable tbl2 = TBL. clone (); datarow [] DRS = TBL. select ("capital like '%" + Capital + "%'"); foreach (VAR item in DRS) {tbl2.rows. add (item [0], item [1], item [2]);} return tbl2;} return TBL ;}}}

This code is simple, that is, returning a datatable.

3. Add some configuration files

3.1,Modify web. config

 
<? XML version = "1.0" encoding = "UTF-8"?> <Configuration> <configsections> <! -- Add fluorinefx configuration section information --> <sectiongroup name = "fluorinefx"> <section name = "Settings" type = "fluorinefx. configuration. xmlconfigurator, fluorinefx "requirepermission =" false "/> </sectiongroup> </configsections> <fluorinefx> <Settings> </fluorinefx> <system. web>  

3.2,Create a WEB-INF/flex directory and create two file remoting-config.xml, services-config.xml

Remoting-config.xml content

 
<? XML version = "1.0" encoding = "UTF-8"?> <Service id = "remoting-service" class = "flex. messaging. Services. remotingservice" messagetypes = "flex. messaging. Messages. remotingmessage"> <! -- Do not change <adapters> section --> <adapters> <adapter-definition id = "DOTNET" class = "fluorinefx. remoting. remotingadapter "default =" true "/> </adapters> <default-channels> <channel ref =" My-AMF "/> </default-channels> <destination ID =" fluorine "> <Properties> <source> * </source> </Properties> </destination> </service>

Services-config.xml content

<? XML version = "1.0" encoding = "UTF-8"?> <Services-config> <services> <service-include file-Path = "remoting-config.xml"/> </services> <channels> <channel-definition id = "My-AMF" Class = "MX. messaging. channels. amfchannel "> <endpoint uri =" http: // {server. name }:{ server. port}/{context. root}/gateway. aspx "class =" flex. messaging. endpoints. amfendpoint "/> <Properties> <legacy-collection> true </legacy-collection> </Properties> </channel-definition> </channels> </services-config>

The directory structure is as follows:

4. Write the flash caller

Import Org. bytearray. remoting. service; import Org. bytearray. remoting. pendingcall; import Org. bytearray. remoting. events. resultevent; import Org. bytearray. remoting. events. faultevent; var gatewayurl: String = "http: // localhost: 7796/gatewayurl. aspx "; if (root. loaderinfo. parameters. remotinggatewaypath! = NULL) {gatewayurl = root. loaderinfo. parameters. remotinggatewaypath + "/gateway. aspx ";} var service: service = new service (" datatabledemo. dataservice ", gatewayurl, objectencoding. amf3); var RPC: pendingcall = service. getcountries ("B"); RPC. addeventlistener (resultevent. result, success); RPC. addeventlistener (faultevent. fault, error); function success (pevt: resultevent): void {txtresult. TEXT = "current Gateway path:" + gatewayurl + "\ n call successful. The following data is returned: \ n"; var Len: Int = pevt. result. length; var I: Int = 0; for (I = 0; I <Len; I ++) {txtresult. appendtext ("ID:" + pevt. result [I]. ID + ", Country:" + pevt. result [I]. country + ", Capital:" + pevt. result [I]. capital + "\ n") ;}} function error (pevt: faultevent): void {txtresult. TEXT = "current Gateway path:" + gatewayurl + "\ n call failed. The following is the details: \ n"; txtresult. appendtext (pevt. fault. description );}

Run:

Sample source file download: http://cid-2959920b8267aaca.office.live.com/self.aspx/Flash/01.DataTable.rar

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.