简体   繁体   English

Flex 4.5远程对象

[英]Flex 4.5 remoting objects

I am very new to remoting in flex. 我对于在flex中进行远程处理非常陌生。 I am using flex 4.5 and talking to a web application built by someone else on the team using AMF. 我正在使用flex 4.5,并与团队中其他人使用AMF构建的Web应用程序进行通讯。 They have used Zend_AMF to serialize and unserialize the data. 他们使用Zend_AMF来序列化和反序列化数据。

One of the main issues I am facing at the moment is that I will need to talk to a lot of services (about 60 or so). 我目前面临的主要问题之一是,我需要与很多服务(大约60项左右)进行交流。

From examples on remoting I have seen online and from adobe, it seems that I need to define a remoting object for EACH service: 从网上看到的远程处理示例和Adobe看来,似乎需要为每个服务定义一个远程处理对象:

<mx:RemoteObject id="testservice" fault="testservice_faultHandler(event)" showBusyCursor="true" destination="account"/>

With so many services, I think I might have to define about 60 of those, which I don't think is very elegant. 有这么多服务,我想我可能必须定义其中的60个,我认为这不是很优雅。

At the same time, I have been playing with Pinta to test out the AMF endpoint. 同时,我一直在与Pinta一起测试AMF端点。 Pinta seems to be able to allow one to define an arbitary amount of services, methods and parameters without any of these limitations. Pinta似乎可以允许定义任意数量的服务,方法和参数,而没有任何这些限制。 Digging through the source, I find that they have actually drilled down deep into the remoting and are handling a lot of low level stuff. 深入研究源代码,我发现他们实际上已经深入到了远程处理中,并且正在处理许多底层内容。

So, the question is, is there a way to approach this problem without having to define loads or remoteobjects and without having to go down too deep and start having to handling low level remoting events ourselves? 因此,问题是,有没有一种方法可以解决此问题而不必定义负载或远程对象,而不必深入研究并自己开始处理低级远程处理事件?

Cheers 干杯

It seems unusual for an application to require that many RemoteObjects. 对于一个应用程序来说,需要那么多RemoteObjects似乎很不寻常。 I've worked on extremely large applications, and we typically end up with no more than ~6-10 RemoteObject declarations. 我已经在超大型应用程序上进行过工作,并且最终通常只用不超过6-10个RemoteObject声明即可。

Although you don't give a lot of specifics in your post about the variations of RemoteObjects, I suspect you may be confusing RemoteObject with Operation . 尽管您没有在文章中提供有关RemoteObjects变体的很多细节,但我怀疑您可能会将RemoteObjectOperation混淆了。

You typically declare a RemoteObject instance for every end-point in your application. 通常,您为应用程序中的每个端点声明一个RemoteObject实例。 However, that endpoint can (and normally does) expose many different methods to be invoked. 但是,该端点可以(并且通常确实)公开许多要调用的方法。 Each of these server-side methods gets results in a client-side Operation . 这些服务器端方法中的每一个都在客户端Operation获得结果。

You can explicitly declare these if you wish, however the RemoteObject builds Operation s for you if you don't declare them: 如果愿意,可以显式声明它们,但是,如果不声明它们,RemoteObject会为您构建Operation

 var remoteObject:RemoteObject;
 // creates an operation for the saveAccount RPC call, and invokes it, 
 // returning the AsyncToken
 var token:AsyncToken = remoteObject.saveAccount(account); 
 token.addResponder(this); 
  //... etc

If you're interacting with a single server layer, you can often get away with a single RemoteObject, pointing to a single destination on the API, which exposes many methods. 如果您正在与单个服务器层进行交互,则通常可以使用单个RemoteObject来指向API上的单个目标,该方法公开了许多方法。 This is approach is often referred to as an API Façade, and can be very useful, if backed with a solid dependency injection discipline on the API. 这种方法通常被称为APIFaçade,如果在API上具有扎实的依赖项注入准则,则该方法非常有用。

Another common approach is to segregate your API methods by logical business area, eg., AccountService, ShoppingCartService, etc. This has the benefit of being able to mix & match protocols between services (eg., AccountService may run over HTTPS). 另一种常见的方法是按逻辑业务区域(例如AccountService,ShoppingCartService等)分隔API方法。这样做的好处是能够在服务之间混合和匹配协议(例如AccountService可以在HTTPS上运行)。

How you choose to split up these RemoteObjects is up to you. 您如何选择拆分这些RemoteObjects由您决定。 However, 60 in a single applications sounds a bit suspect to me. 但是,在一个应用程序中有60个听起来让我有些怀疑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM