[Rails] [ANN] WebserviceHelper
leon breedt
bitserf at gmail.com
Sun Jan 30 07:54:22 GMT 2005
Hello fellow Railers,
I've written a WebserviceHelper which I thought some folks may find useful.
What does it do?
=============
Provides an easy way to drop in SOAP-based web services into your
controllers. It can generate typed WSDL for you, which means people
using .NET can use your web service and they'll still get their nice
"int", "bool", "CustomStruct" types in their C#-side API.
How does it work?
==============
Its pretty non-intrusive. Declare that you are using the helper in
your controller, and indicate which actions are going to serve as
"entry points" (ports in WSDL terminology) to your API.
Example:
class ApiController < ApplicationController
helper :webservice
wsdl_port :person, PersonApi.new
end
What this does is generate the :person action, installing a filter
object to dispatch SOAP actions when /api/person is accessed by
clients. It also creates "wsdl" action accessible via /api/wsdl, which
will output a WSDL file for the API.
To get the typing right, you need to annotate attributes and methods
in your PersonApi class to indicate the desired types for method input
parameters and return values.
Example:
class PersonApi
extend WebService
wsdl
def some_method_with_no_parameters_or_interesting_return_values
end
wsdl :out => [[Integer]]
def method_returning_int_array
[1, 2, 3]
end
wsdl :in => [String]
def method_expecting_string(str)
end
end
See http://blog.xeraph.org/software/WebserviceHelper/doc/ for more
details on how it hangs together.
Where do I get it?
==============
http://blog.xeraph.org/software/WebserviceHelper/WebserviceHelper-0.1.tar.gz.
Just extract over your Rails app, contains
app/helper/webservice_helper.rb and lib/web/service.rb.
The bulk of the code lies in lib/web/service.rb, and the vast majority
of code in there is just to do with mapping between SOAP, WSDL and
Ruby types. Someone more knowledgeable in this area, feel free to
criticize the implementation, as I'm sure mine sucks :)
I don't believe you about .NET interoperability, how do I test that?
==================================================
Have Mono or .NET framework installed (I've only testetd on Mono though).
Do:
$ wget http://localhost:3000/controller/wsdl
$ mv wsdl Something.wsdl
$ wsdl -o Something Something.wsdl
$ vi SomethingService.cs
... add a Main() that calls methods on a SomethingService instance ...
$ mcs -reference:System.Web.Services SomethingService.cs
$ mono SomethingService.exe
Comments, bug reports, suggestions welcome!
Leon
More information about the Rails
mailing list