Rails的ActionWebService提供SOAP服务

REST is very much the way forward as far as Rails in concerned, but there are still plenty of people who need to access a SOAP api, or who have to provide one to third parties. Rails 2.0 dropped Action Web Service from core, with the promise that all you had to do to get it back was to install the gem.

There’s a little more to it than gem install actionwebservice though, and this is what we did.

Getting the source

We checked out the source from http://svn.rubyonrails.org/rails/ousted/actionwebservice/ into our vendor/rails folder (we have all of the rails gems frozen there).

Loading the framework

There are 2 things to do here.
First, above the Rails::Initializer.run block put

class Rails::Configuration
  attr_accessor :action_web_service
end

Next, add

config.frameworks += [ :action_web_service]
config.action_web_service = Rails::OrderedOptions.new
config.load_paths += %W( #{RAILS_ROOT}/app/apis )

This tells Rails that you do want to load Action Web Service, creates a thing for its settings to be contained in and makes Rails look in the apis folder when it needs to find an undefined constant.

Running our tests

Having done this your app should run. There’s one more thing left to do so that you can run your tests. Crack open your test_helper.rb file and add

require 'action_web_service/test_invoke'

below where it says require 'test_help'. This essentially allows you to use the invoke method in your test cases.

Happy Ending

Relax, make yourself a cup of tea. You’ve re-enabled SOAP in your Rails 2.0 app and it didn’t even take 5 minutes.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值