惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
Y
Y Combinator Blog
月光博客
月光博客
IT之家
IT之家
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
L
LangChain Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
博客园 - Franky
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
V
Visual Studio Blog
小众软件
小众软件
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium

博客园 - 幸福★星

开心网外挂,开心网自动管理程序,现已经开发完成 Flex 图片 幻灯片效果初探 FDS.SWC 下载 解决使用FluorineFx实现Remoting通讯时 报 "Channel definition, mx.messaging.channels.RTMPChannel, can not be found" 错的问题 [转载]Flex 2.0 实现SWF全屏 - 幸福★星 [原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (四) [原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (三) [原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (一) [原创]简单的读写注册表配置类 [原创]C#不调用API读写INI文件类 [原创]简单的XML配置文件读写类 VB 6.0 利用CopyMemory实现 指针功能 Sql Server 2000 中 将 0,1 字段,换成 是,否 的查询语句 [原创]C# 操作Excel的类 MSN病毒"性感相册"一个变种的手工杀毒方法 TFS 查看工作区,删除工作区,删除项目 开如使用TFS VS.NET 2005 SP1 安装注意 C# 系统热键类的修正
[原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (二)
幸福★星 · 2007-12-10 · via 博客园 - 幸福★星

版权由http://xingfustar.cnblogs.com/所有,转载请注明出处,XingFuStar 2007年12月11日

三、简单数据类型通讯(http://xingfustar.cnblogs.com/)

    学习一门语言,大多以Hello Word开始,我们也以Hello Word为例, 讲解一下

Flex 与 Asp.Net 通过 Remoting 方式通讯的方法。

1、.NET服务器端程序(http://xingfustar.cnblogs.com/)
    
    在新建的.NET网站的 App_Code文件夹下,Sample.cs 文件,这是由模板为我们创建的。我们可以防照它,在 App_Code下新建一个 RemotingSample.cs文件,
    
    接下来我们编写一个 HelloWord 函数

public string HelloWord()
{
    
return "Hello Word!";
}

    .NET 端工作暂时告一段落, 接下来我们来试计Flex端

2、Flex客户端程序(http://xingfustar.cnblogs.com/)

    在 Design 模式下,添加一个 Text文本控件,id为txtHelloWord,txt属性为空,添加一个 Button控件,id为btnHelloWord,Label属性为 HelloWord
    在 Source 模式下,加入如下代码

<mx:Script>
        
<![CDATA[
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.controls.Alert;
        
            public function RemoteResult(re:ResultEvent):void
            { 
                var str:String = re.result as String;
                this.txtHelloWord.text = str;
                
            }
        
            public function RemoteFault(re:FaultEvent):void
            {
                Alert.show("Message:" + re.fault.faultString,"出错");
            }           
        
]]>
    
</mx:Script><!--这里Source 对应.NET类,前面是命名空间,后面是类名 source = 命名空间.类名-->
    
<mx:RemoteObject 
        
id="sampleRemoteObject"
        destination
="fluorine"
        source
="RemotingSample.RemotingSample"
        showBusyCursor
="true">
        
        
<!--这里是.NET中的方法,name = 方法名 -->
        
<mx:method name="HelloWord" result="RemoteResult(event)" fault="RemoteFault(event)"/>        
    
</mx:RemoteObject>

    
    在 mx:Button 标签中添加属性 click="sampleRemoteObject.HelloWord()"

    运行Flex程序,在浏览器中查看效果 

四、带参数的通讯(http://xingfustar.cnblogs.com/)

    有了上面的基础,我们进行下扩展,做一个稍稍复杂些,带参数的方法:

1、.NET服务器端程序(http://xingfustar.cnblogs.com/)

    在.NET服务器端,RemotingSample类中添加一个新的方法:

public string SayHello(string name)
{
    
return "Hello " + name + "!";
}


2、Flex客户端程序(http://xingfustar.cnblogs.com/)

    在 Design 模式下添加,添加一个 Text文本控件,id为txtSayHello,txt属性为空,添加一个 Button控件,id为btnSayHello,Label属性为 SayHello,添加一个Label,text属性为name:,添加一个

TextInput, id为txtName
    
    在 Source 模式下, 修改 mx:RemoteObject 标签,添加 
    <mx:method name="SayHello" result="RemoteResult(event)" fault="RemoteFault(event)"/> 
    修改脚本中 RemoteResult 方法,代码如下

            public function RemoteResult(re:ResultEvent):void
            { 
                
switch(re.currentTarget.name)
                {
                    
case "HelloWord":
                        var str:String 
= re.result as String;
                        
this.txtHelloWord.text = str;
                        
break;
                    
case "SayHello":
                        str 
= re.result as String;
                        
this.txtSayHello.text = str;
                        
break;
                }
                
            }

    在 mx:Button (SayHello) 标签中添加属性 click="sampleRemoteObject.SayHello(this.txtName.tex)"

    运行Flex程序,在浏览器中查看效果 

附件:完整代码 http://xingfustar.cnblogs.com/)
1、.NET端代码

/*----------------------------------------------------------------
 * 版权:
http://XingFuStar.cnblogs.com
 * 
 * 文件名: RemotingSample
 * 文件功能描述: .NET与Flex通讯DEMO
 * 
 * 作者:XingFuStar
 * 日期:2007年12月11日
 * 
 * 当前版本:V1.0.0
 * 
 * 修改日期:
 * 修改内容:
 *---------------------------------------------------------------
*/using System;
using com.TheSilentGroup.Fluorine;
using System.Collections.Generic;namespace RemotingSample
{
    [RemotingService(
"Fluorine sample service")]
    
public class RemotingSample
    {
        
public RemotingSample()
        {
            
//请不要删除以下信息
            
//版权:http://XingFuStar.cnblogs.com
        }public string HelloWord()
        {
            
return "Hello Word!";
        }
public string SayHello(string name)
        {
            
return "Hello " + name + "!";
        }
    }
}

2、Flex端MXML代码

<?xml version="1.0" encoding="utf-8"?>
<!--
* 版权:http://XingFuStar.cnblogs.com
*
* 作者:XingFuStar
* 日期:2007年12月11日
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"><mx:Script>
        
<![CDATA[
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.controls.Alert;
        
            public function RemoteResult(re:ResultEvent):void
            { 
                switch(re.currentTarget.name)
                {
                    case "HelloWord":
                        var str:String = re.result as String;
                        this.txtHelloWord.text = str;
                        break;
                    case "SayHello":
                        str = re.result as String;
                        this.txtSayHello.text = str;
                        break;
                }
                
            }
        
            public function RemoteFault(re:FaultEvent):void
            {
                Alert.show("Message:" + re.fault.faultString,"出错");
            }           
        
]]>
    
</mx:Script><!--这里Source 对应.NET类,前面是命名空间,后面是类名 source = 命名空间.类名-->
    
<mx:RemoteObject 
        
id="sampleRemoteObject"
        destination
="fluorine"
        source
="RemotingSample.RemotingSample"
        showBusyCursor
="true">
        
<!--这里是.NET中的方法,name = 方法名 -->
        
<mx:method name="HelloWord" result="RemoteResult(event)" fault="RemoteFault(event)"/>    
        
<mx:method name="SayHello" result="RemoteResult(event)" fault="RemoteFault(event)"/>            
    
</mx:RemoteObject><mx:Text x="38" y="25" id="txtHelloWord"/>
    
<mx:Button x="38" y="51" label="HelloWord" id="btnHelloWord0" click="sampleRemoteObject.HelloWord()"/>
    
    
<mx:Text x="38" y="105" id="txtSayHello"/>
    
<mx:Label x="38" y="131" text="name:"/>
    
<mx:TextInput x="88" y="129" id="txtName"/>
    
<mx:Button x="256" y="129" label="SayHello" id="btnSayHello" click="sampleRemoteObject.SayHello(this.txtName.text)"/>
</mx:Application>

本节完成!

FAQ:
    一、为什么我在Flex下运行了程序,打开的页面连不上.NET
        查看打开页面的地址,是以“File”开头,还是以“HTTP”开头,想通过Remoting连接,生成的SWF必须运行在服务器模式下,而不是文件模式

版权由http://xingfustar.cnblogs.com/所有,转载请注明出处,XingFuStar 2007年12月11日