ActionWebService with Rails 2.2
February 8th, 2009
I encountered a trick for young players the other day when providing XML-RPC web service support within a Rails application.
Since Rails 2.0 was introduced, RESTful web services via ActiveResource have been supported in preference to SOAP or XML-RPC web services. Indeed, ActionWebService was dropped from Rails when version 2.0 was released.
However, there are times when the need to provide an interface to another application mandates the use of SOAP or XML-RPC. Recently I had a need to provide an XML-RPC web service server within a Rails application. Fortunately, a version of ActionWebService has been kept up to date on GitHub together with instructions for implementing it.
As I was developing my support for XML-RPC calls, I found chapter 25 of Thomas and Hansson’s “Agile Web Development with Rails” (second edition) invaluable.
For simplicity’s sake, let’s say my controller was:
class BackendController < ApplicationController wsdl_service_name 'Backend' web_service_api BackendApi web_service_scaffold :invoke if Rails.env == 'development' def foo_bar(args) # method code goes here end end
And here is an XML-RPC test client:
require 'xmlrpc/client' require 'pp' server = XMLRPC::Client.new2("http://example.com/backend/api") result = server.call("FooBar", ["arg1", "arg2", "arg3"]) pp result
Notice that the call is to a method called “FooBar” whereas the method within the Rails controller is called “foo_bar”. If you’re like me you will have originally fallen into the trap of assuming that the remote call will have the same name as the controller method rather than the camel case equivalent.
Navigation
Latest Blog Posts
- 24 Jun 2011: Rails Camp 9
- 13 May 2011: Committed Stand-Ups
- 27 Apr 2011: On Agile
- 5 Apr 2011: Maintaining a Legacy Rails App
- 4 Mar 2011: Reflections on YOW 2010 Conference
Syndication
Tags
agile bundler capgun capistrano community conference consulting css deployment dsl estimation jaoo javascript legacy apps osdc pdf planning prawn rails railscamp reflections rorosyd ruby ruby tracker rubygems rvm standups syntax highlighting testing unconference wds08 xml yow
Comments
None yet.
Post a Comment
Please use your real name and be respectful. Textile formatting is supported.