Rails开发人员如何与Flex前端交谈?

时间:2021-01-18 13:45:13

I'm looking at Rails development as a backend to a Flex application and am trying to figure out the communication layer between the Rails app and the Flash Player. All of the things I am finding suggest using SOAP web services to communicate.

我正在将Rails开发视为Flex应用程序的后端,并试图弄清楚Rails应用程序和Flash Player之间的通信层。我发现的所有内容都建议使用SOAP Web服务进行通信。

However, Flash supports AMF which is nice and fast (and native). Is there any way of communicating over AMF from a Rails app, whilst supporting all the "nice" things about AMF (automatic type conversion, data push etc).

但是,Flash支持AMF,它既漂亮又快速(和原生)。有没有办法通过Rails应用程序通过AMF进行​​通信,同时支持AMF的所有“好”的东西(自动类型转换,数据推送等)。

7 个解决方案

#1


3  

There is WebORB or RubyAMF which you can use to respond in AMF from Rails, the approaches are a bit different for each one so it depends on your needs. RubyAMF is discussed in the closing chapters of the Flexible Rails eBook which is a good resource on using Rails with Flex.

您可以使用WebORB或RubyAMF在Rails中使用AMF进行​​响应,每种方法都有所不同,因此它取决于您的需求。 Ruby RFS在Flexible Rails eBook的最后几章中讨论,这是使用Rails with Flex的一个很好的资源。

#2


2  

I'm in the middle of writing a rails/flex application and we're moving to using a JSON communication within the REST framework. Simple HTTP requests from the Flex side handling JSON responses seemed like the best way to decouple the client and server. XML is just as easy.

我正在编写rails / flex应用程序,我们正在使用REST框架中的JSON通信。来自Flex端处理JSON响应的简单HTTP请求似乎是解耦客户端和服务器的最佳方式。 XML也很简单。

For what it's worth, we're using the PureMVC framework on the flex side as well, keeping the responses in a client-side model.

对于它的价值,我们也在flex侧使用PureMVC框架,将响应保持在客户端模型中。

#3


1  

You wouldn't use SOAP web services but rather 'native' REST web services, which are native in Rails. The book quoted by DEFusion above is actually about that: how to use a FLEX client as the front-end of a Rails application using REST (meaning XML).

您不会使用SOAP Web服务,而是使用“本机”REST Web服务,这些服务在Rails中是本机的。以上DEFusion引用的书实际上是关于:如何使用FLEX客户端作为使用REST(意味着XML)的Rails应用程序的前端。

The AMF protocol has primarily been built by Adobe as a binary protocol to allow FLEX front-ends to talk to CodeFusion and of course Java server applications. It's not free, apart from using Adobe's BlazeDS for which you actually won't have much support. And then of course, you'll have to choose a plugin capable of talking to BlazeDS using the AMF protocol (again, see DEfusion's posts) and rely on it.

AMF协议主要由Adobe构建为二进制协议,允许FLEX前端与CodeFusion以及Java服务器应用程序通信。它不是免费的,除了使用Adobe的BlazeDS,你实际上没有太多的支持。当然,你必须选择一个能够使用AMF协议与BlazeDS对话的插件(再次参见DEfusion的帖子)并依赖它。

You'd be surprised how well direct Flex to Rails via REST works, plus you don't have to rely on third-parties. I'd recommend you try it.

你会惊讶地发现,通过REST直接将Flex转换为Rails,而且你不必依赖第三方。我建议你尝试一下。

Hope this helps

希望这可以帮助

#4


1  

Go with RubyAMF if you want an MVC style interaction with contollers that can respond to/generate AMF.

如果您希望与可以响应/生成AMF的控制器进行MVC样式交互,请使用RubyAMF。

Use WebOrb for any other style, including direct access to model objects.

将WebOrb用于任何其他样式,包括直接访问模型对象。

#5


1  

I've built apps using all three methods (WebOrb, RubyAMF, REST)...

我使用所有三种方法(WebOrb,RubyAMF,REST)构建了应用程序......

WebOrb for Rails is pretty much dead, it hasn't been updated in quite sometime. That said I was able to create a bit of Flex/Ruby magic that makes Flex access to Rails' model objects transparent... if you're interested I'll dig it up and send it to you.

WebOrb for Rails已经死了,它已经很久没有更新了。这就是说我能够创建一些Flex / Ruby魔法,使得Flex访问Rails的模型对象变得透明......如果你有兴趣我会把它挖出来发送给你。

RubyAMF is nice, but not as Flexible (ha!) as WebOrb.

RubyAMF很好,但不像WebOrb那样灵活(哈!)。

REST returning JSON is a snap, and if I have to build another one of these (I hope not) that's what I'll continue to use.

REST返回JSON是一个快照,如果我必须构建另一个(我希望不是)这是我将继续使用。

YMMV.

#6


0  

There's a Rails plugin called WebORB for Ruby on Rails which uses remoting with AMF.

有一个名为WebORB的Rails插件,用于Ruby on Rails,它使用AMF进行​​远程处理。

#7


0  

You can use WebORB or RubyAMF, or just plain XML - Rails is pretty smart when it comes to XML, with a few gotchas here and there.

您可以使用WebORB或RubyAMF,或者只使用简单的XML - Rails在XML方面非常聪明,并且有一些问题。

We use XML to speak between our Rails apps and our Flex web application, almost exclusively. It's pretty simple.

我们使用XML几乎完全在我们的Rails应用程序和我们的Flex Web应用程序之间说话。这很简单。

For retrieving data from your Rails app, just create an HTTPService with result_type of e4x, and call your url. In your rails controller, do something like:

要从Rails应用程序中检索数据,只需创建一个result_type为e4x的HTTPService,然后调用您的URL。在您的rails控制器中,执行以下操作:

def people
  render :xml => Person.all.to_xml
end

Sometimes, Rails will add the tag to the end. If this happens, change your controller to:

有时,Rails会将标记添加到最后。如果发生这种情况,请将控制器更改为:

def people
  render :xml => Person.all.to_xml.target!
end

If you want to send data to your Rails app, it's just as easy..

如果你想将数据发送到你的Rails应用程序,那就简单了..

<mx:HTTPService id="theservice" url="http://localhost:3000/svc/add_person" method="POST">
 <mx:request>
  <person>
   <first>Firstname</first>
   <last>Lastname</last>
  </person>
 </request>
</HTTPService>

and in your controller:

在你的控制器中:

def add_person
  p=Person.create(params[:person])
  render :xml => {:result => "Success"}.to_xml.target!
end
  • Kevin

#1


3  

There is WebORB or RubyAMF which you can use to respond in AMF from Rails, the approaches are a bit different for each one so it depends on your needs. RubyAMF is discussed in the closing chapters of the Flexible Rails eBook which is a good resource on using Rails with Flex.

您可以使用WebORB或RubyAMF在Rails中使用AMF进行​​响应,每种方法都有所不同,因此它取决于您的需求。 Ruby RFS在Flexible Rails eBook的最后几章中讨论,这是使用Rails with Flex的一个很好的资源。

#2


2  

I'm in the middle of writing a rails/flex application and we're moving to using a JSON communication within the REST framework. Simple HTTP requests from the Flex side handling JSON responses seemed like the best way to decouple the client and server. XML is just as easy.

我正在编写rails / flex应用程序,我们正在使用REST框架中的JSON通信。来自Flex端处理JSON响应的简单HTTP请求似乎是解耦客户端和服务器的最佳方式。 XML也很简单。

For what it's worth, we're using the PureMVC framework on the flex side as well, keeping the responses in a client-side model.

对于它的价值,我们也在flex侧使用PureMVC框架,将响应保持在客户端模型中。

#3


1  

You wouldn't use SOAP web services but rather 'native' REST web services, which are native in Rails. The book quoted by DEFusion above is actually about that: how to use a FLEX client as the front-end of a Rails application using REST (meaning XML).

您不会使用SOAP Web服务,而是使用“本机”REST Web服务,这些服务在Rails中是本机的。以上DEFusion引用的书实际上是关于:如何使用FLEX客户端作为使用REST(意味着XML)的Rails应用程序的前端。

The AMF protocol has primarily been built by Adobe as a binary protocol to allow FLEX front-ends to talk to CodeFusion and of course Java server applications. It's not free, apart from using Adobe's BlazeDS for which you actually won't have much support. And then of course, you'll have to choose a plugin capable of talking to BlazeDS using the AMF protocol (again, see DEfusion's posts) and rely on it.

AMF协议主要由Adobe构建为二进制协议,允许FLEX前端与CodeFusion以及Java服务器应用程序通信。它不是免费的,除了使用Adobe的BlazeDS,你实际上没有太多的支持。当然,你必须选择一个能够使用AMF协议与BlazeDS对话的插件(再次参见DEfusion的帖子)并依赖它。

You'd be surprised how well direct Flex to Rails via REST works, plus you don't have to rely on third-parties. I'd recommend you try it.

你会惊讶地发现,通过REST直接将Flex转换为Rails,而且你不必依赖第三方。我建议你尝试一下。

Hope this helps

希望这可以帮助

#4


1  

Go with RubyAMF if you want an MVC style interaction with contollers that can respond to/generate AMF.

如果您希望与可以响应/生成AMF的控制器进行MVC样式交互,请使用RubyAMF。

Use WebOrb for any other style, including direct access to model objects.

将WebOrb用于任何其他样式,包括直接访问模型对象。

#5


1  

I've built apps using all three methods (WebOrb, RubyAMF, REST)...

我使用所有三种方法(WebOrb,RubyAMF,REST)构建了应用程序......

WebOrb for Rails is pretty much dead, it hasn't been updated in quite sometime. That said I was able to create a bit of Flex/Ruby magic that makes Flex access to Rails' model objects transparent... if you're interested I'll dig it up and send it to you.

WebOrb for Rails已经死了,它已经很久没有更新了。这就是说我能够创建一些Flex / Ruby魔法,使得Flex访问Rails的模型对象变得透明......如果你有兴趣我会把它挖出来发送给你。

RubyAMF is nice, but not as Flexible (ha!) as WebOrb.

RubyAMF很好,但不像WebOrb那样灵活(哈!)。

REST returning JSON is a snap, and if I have to build another one of these (I hope not) that's what I'll continue to use.

REST返回JSON是一个快照,如果我必须构建另一个(我希望不是)这是我将继续使用。

YMMV.

#6


0  

There's a Rails plugin called WebORB for Ruby on Rails which uses remoting with AMF.

有一个名为WebORB的Rails插件,用于Ruby on Rails,它使用AMF进行​​远程处理。

#7


0  

You can use WebORB or RubyAMF, or just plain XML - Rails is pretty smart when it comes to XML, with a few gotchas here and there.

您可以使用WebORB或RubyAMF,或者只使用简单的XML - Rails在XML方面非常聪明,并且有一些问题。

We use XML to speak between our Rails apps and our Flex web application, almost exclusively. It's pretty simple.

我们使用XML几乎完全在我们的Rails应用程序和我们的Flex Web应用程序之间说话。这很简单。

For retrieving data from your Rails app, just create an HTTPService with result_type of e4x, and call your url. In your rails controller, do something like:

要从Rails应用程序中检索数据,只需创建一个result_type为e4x的HTTPService,然后调用您的URL。在您的rails控制器中,执行以下操作:

def people
  render :xml => Person.all.to_xml
end

Sometimes, Rails will add the tag to the end. If this happens, change your controller to:

有时,Rails会将标记添加到最后。如果发生这种情况,请将控制器更改为:

def people
  render :xml => Person.all.to_xml.target!
end

If you want to send data to your Rails app, it's just as easy..

如果你想将数据发送到你的Rails应用程序,那就简单了..

<mx:HTTPService id="theservice" url="http://localhost:3000/svc/add_person" method="POST">
 <mx:request>
  <person>
   <first>Firstname</first>
   <last>Lastname</last>
  </person>
 </request>
</HTTPService>

and in your controller:

在你的控制器中:

def add_person
  p=Person.create(params[:person])
  render :xml => {:result => "Success"}.to_xml.target!
end
  • Kevin