加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

FluorineFX框架下的.NET和FLEX当中数据转换(自定义类型)

发布时间:2020-12-15 01:03:47 所属栏目:百科 来源:网络整理
导读:一些基础的数据,比如int,string都是直接可以转换过去的,不需要其他的步骤,只需要配置好了,就可以转换。 这篇博文,学习如何转化自定义类型,也就是所谓的类。 使用这个有两种方法 我首先把.NET当中的代码贴出来 using System;using System.Collections.

一些基础的数据,比如int,string都是直接可以转换过去的,不需要其他的步骤,只需要配置好了,就可以转换。

这篇博文,学习如何转化自定义类型,也就是所谓的类。

使用这个有两种方法

我首先把.NET当中的代码贴出来

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FluorineFx;

/// <summary>
///studentLab 的摘要说明
/// </summary>
namespace School.Po
{ 
    [RemotingService]
    public class StudentLab
    {
        public string studentId { get; set; }
        public int floorIndex { get; set; }
        public int floorFid { get; set; }
        public StudentLab()
        {
        }
        public StudentLab getStudentLab()
        {
            StudentLab sl = new StudentLab();
            sl.studentId = "12345";
            sl.floorIndex = 3;
            sl.floorFid = 45;
            return sl;
        }
    }
}


第一种:在FLEX中

只需要添加[RemoteClass(alias="School.Po.StudentLab")],在类前面。

package vo
{
	[RemoteClass(alias="School.Po.StudentLab")]
	public class StundetVo
	{
		public function StundetVo()
		{
		}
		public var studentId:String;
		public var floorIndex:int;
		public var floorFid:int;
	}
}

需要注意的是两点,第一点就是刚才说的,添加相应的远程类。第二个就是各个属性之间,名字必须保持一致,包括大小写,否则不知道怎么对应。

我们这个时候,测试一下代码正确性。下面是FLEX一个测试代码。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>

	<fx:Script>
		<![CDATA[
			import mx.rpc.events.ResultEvent;
			
			import vo.StundetVo;
			protected function button1_clickHandler(event:MouseEvent):void
			{
				ro.getStudentLab();
			}

			protected function ro_resultHandler(event:ResultEvent):void
			{
				var s:StundetVo=event.result as StundetVo;
				trace(s.studentId);
				trace(s.floorFid);
				trace(s.floorIndex);
			}

		]]>
	</fx:Script>

	<fx:Declarations>
		<s:RemoteObject id="ro" destination="fluorine" source="School.Po.StudentLab" result="ro_resultHandler(event)"/>
	</fx:Declarations>
	<s:Button x="41" y="24" label="开始" click="button1_clickHandler(event)"/>
</s:Application>
我debug一下,下面是贴图


我们很容易可以看到,result自动转化为我们设计的类。s,下面的数据,也保存着相关属性信息。如果我们删除,远程类,这句话,就会出现以下错误。

TypeError: Error #1009: 无法访问空对象引用的属性或方法。
at test/ro_resultHandler()[D:flrxwpfxsrctest.mxml:22]
at test/__ro_result()[D:flrxwpfxsrctest.mxml:31]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.rpc::AbstractService/dispatchEvent()[E:dev4.0.0frameworksprojectsrpcsrcmxrpcAbstractService.as:333]
at mx.rpc.remoting.mxml::RemoteObject/dispatchEvent()[E:dev4.0.0frameworksprojectsrpcsrcmxrpcremotingmxmlRemoteObject.as:148]
at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:dev4.0.0frameworksprojectsrpcsrcmxrpcAbstractOperation.as:254]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:dev4.0.0frameworksprojectsrpcsrcmxrpcAbstractInvoker.as:318]
at mx.rpc::Responder/result()[E:dev4.0.0frameworksprojectsrpcsrcmxrpcResponder.as:56]
at mx.rpc::AsyncRequest/acknowledge()[E:dev4.0.0frameworksprojectsrpcsrcmxrpcAsyncRequest.as:84]
at NetConnectionMessageResponder/resultHandler()[E:dev4.0.0frameworksprojectsrpcsrcmxmessagingchannelsNetConnectionChannel.as:547]
at mx.messaging::MessageResponder/result()[E:dev4.0.0frameworksprojectsrpcsrcmxmessagingMessageResponder.as:235]


这是第一种方法,不过一些情况下,也会出错。

我们来看第二种方法

2:在.NET当中,修改web.config

不过这个我没有实验成果,还希望有人帮忙指正一下,所有的代码和上面的一样,就除了,没有[RemoteClass(alias="School.Po.StudentLab")]。

在<fluorinefx>
<settings>

下面添加以下配置

<classMappings>
? ? ? ? <classMapping>
? ? ? ? ? <type>School.Po.StudentLab</type>
? ? ? ? ? <customClass>vo.StundetVo</customClass>
? ? ? ? </classMapping>
? ? ? </classMappings>

我没有成果!不知道还有什么其他地方,需要修改不

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读