如何使用 Ruby 和 Savon 执行简单的 Web 服务客户端
我正在尝试使用 Savon 在 Ruby 中开发一个简单的 Web 服务客户端示例。
这是我到目前为止得到的:
class WebServiceController < ApplicationController
def index
puts "web_service: IN"
client = Savon::Client.new do
wsdl.document = "http://www.webservicex.com/CurrencyConvertor.asmx?wsdl"
end
response = client.request :conversion_rate do
soap.body = {
:from_currency => 'USD',
:to_currency => 'EUR'
}
end
puts response.to_hash;
render :text => response.to_hash.to_s
end
end
但是,当我运行该代码时,我得到:
未初始化的常量 Savon::Client
我想我必须添加一些对 Savon 的引用? (我已经安装了相应的gem)。
另外:我在该网络服务中做的事情正确吗?应该有效吗?
谢谢您的宝贵时间!
I'm trying to develop a simple example of a web service client in Ruby using Savon.
This is what I got so far:
class WebServiceController < ApplicationController
def index
puts "web_service: IN"
client = Savon::Client.new do
wsdl.document = "http://www.webservicex.com/CurrencyConvertor.asmx?wsdl"
end
response = client.request :conversion_rate do
soap.body = {
:from_currency => 'USD',
:to_currency => 'EUR'
}
end
puts response.to_hash;
render :text => response.to_hash.to_s
end
end
However, when I run that code I get:
uninitialized constant Savon::Client
I guess I have to add some reference to Savon? (I already installed the corresponding gem).
In addition: am I doing the right thing in that web service? Should it work?
Thank you for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这是 Rails 3 应用程序,请将其添加到您的
Gemfile
中:然后,运行
bundle install
并重新启动您的开发服务器。If this is a Rails 3 application, add this onto your
Gemfile
:Then, run
bundle install
and restart your development server.我想你已经
在文件中添加了某个地方?
I suppose you've added
somewhere in your file?