Setting up a simple Webservice - Why so hard?

Hello everyone.

I want to write a simple webservice in rails, which will accept
requests by a javascript client using XML-RPC.
Knowing very little about webservices in general, I decided first to
set up a couple of simple applications (a server and a client) to
learn how webservices work.
Using rails 2.0, I first followed the instructions here:
and then tweaked my apps to get them working in rails 2.0 as explained

Now, please follow me and have a look if I’m doing something wrong,
'cause I cannot get a single thing working…

I set up a single method, which takes a string and returns an integer
(it does nothing - it’s just to see if it works):

(content of /app/apis/myws_api.rb)
class MywsAPI < ActionWebService::API::Base
inflect_names false

api_method :givenumber, :expects => [:parameter1=>:string], :returns
=> [:int]


(content of /app/controllers/myws_controller.rb)
class MywsController < ApplicationController

web_service_dispatching_mode :layered
web_service :myws,


(content of /app/models/myws_service.rb)
class MywsService < ActionWebService::Base
web_service_api MywsAPI

def givenumber(:parameter1)
    return   1


And that should be all, right?
Now for the client… I just really wanted just to see something
coming out of the webservice in the quickiest and dirtiest way, so I
just scaffolded a Thing object. In its edit action, I just call the
web service and flash it out:

(excerpt from thing_controller.rb)

def edit

@myws_client =,

http://localhost:3000/myws/api’, :handler_name => ‘myws’)
flash[:notice] = @myws_client.givenumber(‘test’)


When I fire things up, something goes wrong. My client gets a most
“HTTP-Error: 500 Internal Server Error”
While mongrel says that there has been a:
“LoadError (Expected [my project path]/app/apis/myws_api.rb to define

Since MywsApi is defined in myws_api.rb, I do not really know what’s
happening here.
I know that the client ‘sees’ the server, because if I try to call the
service with the wrong parameters, example:
@myws_client.givenumber(‘test’, ‘test2’)
I get the error:
givenumber: wrong number of arguments (2 for 1)

So, where am I messing up?
Any help would be much appreciated - Thanks in advance!


On May 22, 9:18 am, Rey9999 [email protected] wrote:

(content of /app/models/myws_service.rb)
class MywsService < ActionWebService::Base
web_service_api MywsAPI

def givenumber(:parameter1)
    return   1


That is syntactically incorrect. It should be def
givenumber(parameter1). In addition for magic autoload to work, you
need to follow the rails naming conventions, so MywsAPI should be
MywsApi (see the error message ?)


Thanks for the quick reply!

But now I get another strange error:
HTTP-Error: 422
:79:in `verify_authenticity_token’
…and so on…

Do I need to configure something to let the webservice run?



Ok, problem solved - I needed to set the options for

Thanks Fred, now it works like a charm!



This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs