FLEX远程连接Fluorinefx

 

 用FLEX远程连接Fluorinefx,主要是用到NetConnection

 

使用工具:VS2008(必须安装了Fluorinefx),FLEX

 

步骤入下:

打开VS2008, 点击菜单  "文件"---->

                                     "新建"---->

                                     "项目"---->

                                     Visual Studio 已安装的模板 选 Fluorinefx ServiceLibrary

 


会建立以下文件:


 

第二个ServiceLibrary123是一个类库,对类库点右键,"添加"---"类",添加一个名为"Test.cs"的类,

using System;
using System.Collections.Generic;
using System.Text;
using FluorineFx;

namespace ServiceLibrary123
{
    /// <summary>
    /// Fluorine sample service.
    /// </summary>
    [RemotingService("Fluorine sample service")]   //这行不能少
    public class Test
    {
       
        public Test()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sName"></param>
        /// <returns></returns>
        public string hello(string sName)
        {
            return "这里是Fluorine端,欢迎你:" + sName;
        }

    }
}

 

然后对着解决方案"ServiceLibrary123"点右键,

为解决方案添加网站 

 "添加"---->"新建网站"---->选"Fluorinefx ASP.NET Web Site"



 

图个方便,我直接把地址填为本地IIS,其实应该和之前我们建的库放在同一个文件夹,不过还是可以使用的.

建立完成后:

 



 

设置http://localhost/Fluorinefx123/为启动项目 ,设置Console.aspx为起始页,即可运行


只要能在运行界面找到Test类和其hello方法,服务器端就算配置成功了

 

 

下面来用FLEX编写客户端

 

打开FLEX  点菜单"File"---->"New"---->"Flex Project", project name 随便起.

 



 添加一个名为RemotingConnection.as的AS类,继承NetConnection类.代码如下

package
{
    import flash.net.NetConnection;
    import flash.net.ObjectEncoding;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.system.Security;
    
    public class RemotingConnection extends NetConnection
    {
        public function RemotingConnection(gatewayUrl:String)
        {
            //设置通信权限
            Security.allowDomain(gatewayUrl);
            //设置数据格式
            this.objectEncoding = ObjectEncoding.AMF0;
            //连接网关
            this.connect(gatewayUrl);
        }
    }

}

 

修改testNetConnection.mxml代码入下

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:Script>
		<![CDATA[
			import flash.display.Sprite;
            import RemotingConnection;
            import flash.net.Responder;
            import mx.controls.Alert;
            
            public var gateway:RemotingConnection;
            public var responder:Responder;

            public var CheckFlag:String = null;

            
            public function init():void
            {
            	//连接网关
       
            //成功连接
            if(this.thisinput.text!="")
            {
            gateway = new RemotingConnection("http://localhost/Fluorinefx123/Gateway.aspx");
            //通讯方法 参数1为要调用的服务器端的方法,
            //参数2为成功和失败时调用的方法,由Responder包装,
            //参数3为要传进的参数,我这里是TextInput的Text
            gateway.call("ServiceLibrary123.Test.hello",new Responder(onResult,onFault),this.thisinput.text);
            }
            else
            {
            	Alert.show("请输入信息");
            }
        }
        
        /***************************
        * 返回成功
        **/
        public function onResult(resultt:String):void
        {
             if(this.thistext.text=="")
            {this.thistext.text=resultt}
            else{
            this.thistext.text=this.thistext.text+"\n"+resultt;
            }
            
          
        }
        
        /***************************
        * 返回失败
        **/
        public function onFault(fault:String):void
        {
           Alert.show(fault);
        }

            


		]]>
	</mx:Script>
	<mx:Panel x="178" y="59" width="269" height="238" layout="absolute" borderStyle="solid" borderColor="#DFE2DD" backgroundColor="#DAEE95" cornerRadius="8" title="连接远程FluorineFx" fontSize="13">
		<mx:Canvas x="0" y="0" width="249" height="184" cornerRadius="8" borderStyle="solid" backgroundColor="#FBFBD6">
			<mx:TextInput x="58" y="7" id="thisinput"/>
			<mx:Label x="8" y="7" text="输入:" width="42" height="20" fontSize="15"/>
			<mx:TextArea x="58" y="40" height="86" id="thistext" editable="false"/>
			<mx:Button x="112" y="134" label="读取" fontSize="14" click="init()"/>
		</mx:Canvas>
	</mx:Panel>
</mx:Application>

 
 运行程序:



 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值