---
title: "Asp.net与Flex交互测试"
author: "njmnjx"
date: "2010-12-20T21:46:49Z"
tags: []
categories: ["Web前端"]
slug: "asp-net-flex"
draft: false
lastmod: "2010-12-20T21:46:49Z"
id: 847570
url: "https://njm.iteye.com/blog/847570"
---

<span style="color:green">//////////////////////////////////////////////////////////////
一、利用asp.net为Flex提供数据服务，flex为前端表现。
二、flex通过三种方式四种代码实现来取数据。分别为
    	HttpService、
	WebService、
	RemoteObject、
	RemoteObjectAMF0。
三、Project文件夹中的
	Vs2010Service提供HttpService、Webservice服务；
        Vs2008RemoteObject提供RemoteObject服务。
四、FluorineFx.NET+RemoteObjectAMF0文件为附加文件。
五、<sessionState cookieless="AutoDetect"></sessionState>
	设置可兼容客户端禁用Cookie(要在Flex项目中传递回sessionid)
六、asmx中使用session需要 如此设置。

七、安装FluorineFx.NET+RemoteObjectAMF0文件下的setup(FluorineFx.NET).exe
	可以将项目模板集成到2005和2008中，不支持vs2010。
八、使用七中的模板建立普通网站（FluorineFx ASP.NET Web Site）项目。
	将Console.aspx设为启动页，可进行类中的方法测试。
九、使用RemoteObjectAMF0时将renaun_com_RemoteObjectAMF0.zip解压把src下的
	com文件夹整体复制到flex项目中；
	注意路径与mxml同路径；
	RemoteObjectAMF0.as中的override public function setCredentials( username:String, password:String):void）修改成override public function setCredentials( username:String, password:String,charset:String=null ):void）
	添加xmlns:renaun="com.renaun.rpc.*"到<mx:Application ……中。
十、使用普通RemoteObject在mxml的同目录下添加services_config.xml文件内容如下：</span>
	
```xml
<?xml version="1.0" encoding="UTF-8"?>
		<services-config>
    		<services>
        		<service id="remoting-service"
                 		class="flex.messaging.services.RemotingService"
                 		messageTypes="flex.messaging.messages.RemotingMessage">
            		<destination id="fluorine">
                		<channels>
                    		<channel ref="my-amf"/>
                		</channels>
                		<properties>
                    		<source>*</source>
                		</properties>
            		</destination>
        		</service>
    		</services>
    		<channels>
        		<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
           		 <endpoint uri="http://localhost:12432/ReomteFlex/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/>
        		</channel-definition>
    		</channels>
		</services-config>
```
	
	<span style="color:green">注：http://localhost:12432/ReomteFlex/Gateway.aspx随项目启动的端口变化。
	
	之后，Flex项目右键-属性-Flex compiler-compiler参数（-locale en_US -services "services_config.xml"）

十一、以上功能使用的前提
	运行vs2008项目、vs2010项目、Flex项目；
	vs2008项目、vs2010项目启动后的端口与本实例建立时的端口不一致，请将变化后的端口相应改变Flex项目中即可。
十二、Flex项目HttpService方式中的URL地址中有一个{sessionid}可以不要，只是为了测试而以，就安vs默认将sessionid放在Cookie即可。
十三、整个流程为：
	输入用户名：njm
	密码：168
	登录成功返回当前sessionid
	之后可点击“带着身份访问”进行测试。
	最后点击“退出”。</span>