1.新建asp.net web工程FlexTest-Compute
WebORB工程目录下的文件(C:\Inetpub\wwwroot\weborb30):
weborb.config 拷贝到FlexTest-Compute工程的根目录
diagnostics.aspx 拷贝到FlexTest-Compute工程的根目录
weborb.dll 拷贝到FlexTest-Compute工程的bin目录
2.引用weborb.dll到FlexTest-Compute项目
3.修改FlexTest-Compute项目的web.config文件,增加:
<httpHandlers>
<add verb="*" path="weborb.aspx" type="Weborb.ORBHttpHandler"/>
<add verb="*" path="codegen.aspx" type= "Weborb.Management.CodeGen.CodegeneratorHttpHandler"/>
</httpHandlers>
4.copy C:\Inetpub\wwwroot\weborb30下的WEB-INF目录到 FlexTest-Compute项目根目录下
5.新建cs文件,添加如下代码:
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>
/// ComputeService 的摘要说明
/// </summary>
public class ComputeService
{
public ComputeService()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public int Compute(int arg1, int arg2)
{
return arg1 + arg2;
}
}
Compute方法实现一个计算2个参数之和的功能。
6.新建flex工程 HelloNet。工程目录是E:\Projects\FlexTest-Compute\FlexTest-Compute\flex,使用ASP.NET的web server,不
用IIS(测试用的就不用劳烦IIS了)
7.修改HelloNet项目的编译属性为:
-locale en_US -services E:\Projects\FlexTest-Compute\FlexTest-Compute\WEB-INF\flex\services-config.xml
8.根据vs.net debug时使用的web server端口,修改HelloNet项目的Build Path和debug,run path :
http://localhost:****/flex/flex_bin/HelloNet.html
在flex application文件中增加代码:
<?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>
浙公网安备 33010602011771号