flash.utils.IExternalized +远程处理Flex 错误 #2004
有一个客户端-服务器基本应用程序。客户端使用简单的远程处理与服务器端进行通信。服务器端可以由WebORB、BlazeDS 或任何其他产品供电。客户端使用FLEX框架。这就是关于技术堆栈的内容。现在,让我们忘记服务器端,只看一下以下客户端
package com.blog.ri
{
import mx.collections.ArrayCollection;
public class MyCollection extends ArrayCollection
{
public function MyCollection(source:Array=null)
{
super(source);
}
}
}
此外,假设我们有以下类并且它映射到服务器端类:
package com.blog.ri
{
[Bindable]
[RemoteClass(alias="com.blog.ri.MyEntity")]
public dynamic class MyEntity
{
private var _myCollection:MyCollection;
public function get myCollection():MyCollection
{
if(_myCollection == null)
_myCollection = new MyCollection();
return _myCollection;
}
public function set myCollection(value:MyCollection):void
{
_myCollection = value;
}
}
}
此外,服务器端服务向客户端公开 void save( MyEntity候选)方法,我在客户端实现了它,如下所示:
package com.blog.ri
{
public class MyService
{
private var _remoteObject:RemoteObject;
public function MyService()
{
var channelSet:ChannelSet = new ChannelSet();
var amfChannel:AMFChannel = new AMFChannel("my-amf", "http://localhost/weborb.aspx");
channelSet.addChannel(amfChannel);
_remoteObject = new RemoteObject("GenericDestination");
_remoteObject.channelSet = channelSet;
_remoteObject.source = "com.blog.ri.MyService";
_remoteObject.getDetailedStatistic.addEventListener("result",onItemSaved);
_remoteObject.addEventListener("fault", onFault);
}
public function save(candidate:MyEntity, responder:IResponder = null ):void
{
var asyncToken:AsyncToken = _remoteObject.save(candidate);
if( responder != null )
asyncToken.addResponder( responder );
}
}
}
最后,我尝试在主 mxml 文件中保存 MyEntity 类的新实例,如下所示:
protected function creationCompleteHandler():void
{
var myService:MyService = new MyService();
var candidate:MyEntity = new MyEntity();
candidate.myCollection = new MyCollection();
myService.save(candidate);
}
就是这样。当我运行代码时,我收到以下异常:
ArgumentError:错误#2004:参数之一无效。在 flash.net::NetConnection/invokeWithArgsArray() 位于 flash.net::NetConnection/call() 位于 mx.messaging.channels::NetConnectionChannel/internalSend()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:281] 在 mx.messaging.channels::AMFChannel/internalSend()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:364] 在 mx.messaging::Channel/send()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\Channel.as:1002] 在 mx.messaging.channels::PollingChannel/send()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.as:394] 在 mx.messaging::ChannelSet/send()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1429] 在 mx.messaging::ChannelSet/channelConnectHandler()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1084] 在 flash.events::EventDispatcher/dispatchEventFunction() 处 flash.events::EventDispatcher/dispatchEvent() 在 mx.messaging::Channel/connectSuccess()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\Channel.as:1148] 在 mx.messaging.channels::AMFChannel/resultHandler()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:576]
如您所见,我扩展了 ArrayCollection 类根据 Adobe 文档,ArrayCollection 实现了 IExternalized 接口。我决定本地化问题并创建一个实现 IExternalized 的简单类。然后,我在其他一些 MyChild 类中扩展了此类,并在 MyEntity 类中定义了 MyChild 属性。在这种情况下,我也收到了上面的异常。是我编写代码的方式有问题还是flex中的错误?
感谢您的任何帮助。 这个问题在我的博客中重复了。
There is a client - server basic application. The client uses a simple remoting to comunicate with the server side. The server side could be powered on WebORB, BlazeDS or any other product. The client side is using the FLEX framework. That is it about a technologies stack. Now, let's forget about the server side and just have a look on the following client side
package com.blog.ri
{
import mx.collections.ArrayCollection;
public class MyCollection extends ArrayCollection
{
public function MyCollection(source:Array=null)
{
super(source);
}
}
}
Additionally, let's assume we have the following class and it is mapped to the server side class:
package com.blog.ri
{
[Bindable]
[RemoteClass(alias="com.blog.ri.MyEntity")]
public dynamic class MyEntity
{
private var _myCollection:MyCollection;
public function get myCollection():MyCollection
{
if(_myCollection == null)
_myCollection = new MyCollection();
return _myCollection;
}
public function set myCollection(value:MyCollection):void
{
_myCollection = value;
}
}
}
Also, the server side service expose for clients the void save(MyEntity candidate) method and I implemented it on the client side as it shown below:
package com.blog.ri
{
public class MyService
{
private var _remoteObject:RemoteObject;
public function MyService()
{
var channelSet:ChannelSet = new ChannelSet();
var amfChannel:AMFChannel = new AMFChannel("my-amf", "http://localhost/weborb.aspx");
channelSet.addChannel(amfChannel);
_remoteObject = new RemoteObject("GenericDestination");
_remoteObject.channelSet = channelSet;
_remoteObject.source = "com.blog.ri.MyService";
_remoteObject.getDetailedStatistic.addEventListener("result",onItemSaved);
_remoteObject.addEventListener("fault", onFault);
}
public function save(candidate:MyEntity, responder:IResponder = null ):void
{
var asyncToken:AsyncToken = _remoteObject.save(candidate);
if( responder != null )
asyncToken.addResponder( responder );
}
}
}
Finally, I tried to save a new instance of the MyEntity class in our main mxml file as it shown below:
protected function creationCompleteHandler():void
{
var myService:MyService = new MyService();
var candidate:MyEntity = new MyEntity();
candidate.myCollection = new MyCollection();
myService.save(candidate);
}
That is it. When I run the code, I received the following exception:
ArgumentError: Error #2004: One of the parameters is invalid. at
flash.net::NetConnection/invokeWithArgsArray() at
flash.net::NetConnection/call() at
mx.messaging.channels::NetConnectionChannel/internalSend()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:281]
at
mx.messaging.channels::AMFChannel/internalSend()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:364]
at
mx.messaging::Channel/send()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\Channel.as:1002]
at
mx.messaging.channels::PollingChannel/send()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.as:394]
at
mx.messaging::ChannelSet/send()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1429]
at
mx.messaging::ChannelSet/channelConnectHandler()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1084]
at flash.events::EventDispatcher/dispatchEventFunction() at
flash.events::EventDispatcher/dispatchEvent() at
mx.messaging::Channel/connectSuccess()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\Channel.as:1148]
at
mx.messaging.channels::AMFChannel/resultHandler()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:576]
As you can see, I extended the ArrayCollection class and according to the Adobe documentation, the ArrayCollection implements the IExternalizable interface. I decided to localize the problem and created a simple class that implements IExternalizable. Then, I extended this class in some other MyChild class and defined the MyChild property in the MyEntity class. In this case, I received the exception above as well. Is there a problem how I wrote the code or it is a bug within flex?
Thanks for any help.
The question is duplicated in my blog.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以尝试:
You could try:
尝试为 MyCollection 添加别名。
我收到了无用的错误#2004,直到我所有实现 IExternalized 的类都有别名。就我而言,这是为了持久化(ViewNavigatorApplicationBase.persistNavigatorState = true),在这种情况下,我必须确保在启动时尽早调用 registerClassAlias,以便在 View.deserializeData() 之前调用。应用程序上的预初始化事件工作正常。
Try adding an alias for MyCollection.
I got the unhelpful Error #2004 until all of my classes implementing IExternalizable had aliases. In my case it was for persistence (ViewNavigatorApplicationBase.persistNavigatorState = true) in which case I had to make sure I called registerClassAlias early enough in the startup to precede View.deserializeData(). The preinitialize event on the app works ok.
您的某些正在(反)序列化的类可能未链接到 Flex 项目中。尝试将以下内容添加到您的主应用程序/模块文件中:
Some of your classes being (de)serialized is probably not linked into Flex project. Try adding following to your main Application/Module file: