AMF 可以用作“另一种输出格式”吗? 来自网络服务?
我正在开发一个 RESTish 服务器项目,该项目可以响应各种格式的 HTTP 请求。 这使我们能够编写面向用户的应用程序并检索当时看起来最方便的格式。 例如,要查看是否有用户登录,我们可以发送:
http://serverurl/Authentication?command=whoami&format=xml
正如您可以想象的,这将返回包含有关登录用户的信息(如果有)的 XML。 我们可以在 json 中获得相同的信息:
http://serverurl/Authentication?command=whoami&format=json
最近,我们一直在讨论添加对 yaml 的支持,因为它在一些 ruby 和 python 开发人员中很受欢迎。 同时,我们一直在讨论在 Flex 中编写原型客户端应用程序(如果您不能从我的问题中看出,这将是我们首次涉足 Flex 开发)。 我确实知道我们可以使用现有的一种格式与 Flex 应用程序进行通信,但是如果我们决定“仅仅因为我们可以”就添加对这些附加格式的支持,是否存在某些因素会使使用 amf 特别困难或与使用 amf 不同输出xml还是json?
I'm working on a RESTish server project that responds to HTTP requests in a variety of formats. This allows us to write user facing applications and retrieve whichever format seems most convenient at the time. For example, to see if there is a user logged in, we can send:
http://serverurl/Authentication?command=whoami&format=xml
As you can imagine, this returns XML that contains information about the logged in user (if any). We can get the same information back in json:
http://serverurl/Authentication?command=whoami&format=json
Recently, we've been discussing adding support for yaml, since it's popular with some ruby and python developers. At the same time, we have been talking about writing a prototype client application in Flex (which, if you can't tell from my question, would be our first foray into Flex development). I do understand that we can use one of our existing formats to communicate with a Flex app, but if we decide to add support for these additional formats "just because we can", is there something that would make using amf especially difficult or different from outputting xml or json?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
AMF 是“操作消息格式”,它只是一种以非常紧凑的二进制格式对数据进行编码的方法。 从严格意义上来说,AMF 并不与 RPC 绑定。 Flex(消费者/生产者)中可用的消息传递功能使用 AMF 对所有消息的数据进行编码,这绝对不是 RPC。
回到您的问题:您使用什么服务器端技术来构建应用程序? 适用于各种平台的 AMF 库的质量和成熟度各不相同。 大多数这些库应该允许您简单地传递要编码的对象并接收字节数组,您可以将其写入与 REST 端点绑定的 HTTP 请求的输出流。
AMF is the Action Message Format and it's simply a way of encoding data in a very compact binary format. AMF is not tied to RPC in any strict sense. The messaging features available in Flex (Consumer / Producer) use AMF to encode the data for all messages and this definitely not RPC..
Back to your question: what server-side technology are you using to build your application? The AMF libraries for various platforms are all of varying quality and maturity. Most of these libraries should allow you to simply pass the object you want to encode and receive byte array that you can write to the output stream of the HTTP request tied to your REST endpoint.
我目前正在开发一个使用 AMF 作为序列化格式的平台,完全按照您建议的方式(在 .Net 平台上)。 我们所做的是:
在客户端,我们使用格式设置为二进制的常规 URLLoader。 loader.data 属性将是一个 ByteArray,并使用 ReadObject,您可以获得序列化的 DTO。 如果您使用 [RemoteClass] 元数据并注册ClassAlias,您将获得相应的类型 - 否则您将获得具有一些动态属性的通用对象。
绕过类型化 DTO 的一个很酷的事情是,我们可以在其上使用常规 XML 或 JSON 序列化程序,从而使格式版本控制变得非常简单。
我还运行了测试,将 ByteArrays 发布回服务器以进行创建/更新,它似乎工作正常。 所以本质上,您现在可以使用 AMF 进行 REST。
我也在考虑将其用于服务器到服务器的通信,因为它重量轻,并且对于序列化复杂类型似乎非常强大。
I am currently working on a platform using AMF as a serialization format in exactly the way you're proposing (on .Net platform). What we do is:
On the client side, we use a regular URLLoader with format set to binary. The loader.data property will be a ByteArray and using ReadObject, you get the serialized DTO. If you use [RemoteClass] metadata and registerClassAlias, you will get the corresponding type - otherwise you get a generic object with some dynamic properties.
The cool thing with taking the detour around a typed DTO is that we can use regular XML or JSON serializers on it, making the format versioning extremely simple.
I have also run tests with posting ByteArrays back to the server for Create/Update and it seems to work fine. So In essence, you can now use AMF for REST.
I am also looking into using this for server to server communication since it is light weight and seems to very robust for serializing complex types.
回答 Vineet Bhatia 的问题:
你检查过 BlazeDS 吗? http://opensource.adobe.com/wiki/display/blazeds/Overview
In response to Vineet Bhatia's question:
Have you checked out BlazeDS? http://opensource.adobe.com/wiki/display/blazeds/Overview
是的,您可以做到这一点,但您必须编写自己的 AMF 序列化器和反序列化器(只需复制 Zend Framework 中的序列化器和反序列化器)。 或者你可以等我完成我的。 我会尽力记住将其发布在这里。
Ya you can do it but you'll have to write your own AMF serializer and deserializer (just copy the one in Zend Framework). Or you can wait for me to finish mine. I'll try to remember to post it here.
AMF 是一种 RPC(远程过程调用)格式,与 SOAP 非常相似,但目标受众不同。 由于过程调用和对象之间存在根本区别,因此 AMF 不只是您的另一种输出格式。
您可能应该将 AMF 视为“Flex Remoting”,而不是使用 REST API 针对 Flex 的输出格式。
打个比方:您是否认为 SOAP 或 XMLRPC 只是 REST API 的另一种输出格式?
AMF is an RPC (Remote Procedure Call) format, much like SOAP, but with a different target audience. Since there's a fundamental difference between a procedure call and an object, AMF is not going to be just another output format for you.
You should probably think of AMF as "Flex Remoting" and not as an output format targeted at Flex using your REST API.
To make an analogy: would you think of SOAP or XMLRPC as just another output format for a REST API?