availability: October 2010

$ gem install actionwebservice
This installed ok, bringing all the older versions of action series gems along with it.
$ ./script/generate web_service ...
It did not have the generator, so much for this solution
$ gem install datanoise-actionwebservice --source http://gems.github.com ./script/generate .... Installed Generators Rubygems: web_service Builtin: controller, helper, integration_test, mailer, metal, migration, model, observer, performance_test, plugin, resource, scaffold, session_migration ....As you can see, it puts its files in /app/services instead of app/api .
$ ./script/generate web_service Item create app/services/ exists app/controllers/ exists test/functional/ create app/services/item_api.rb create app/controllers/item_controller.rb create test/functional/item_api_test.rb
config.gem 'datanoise-actionwebservice', :lib => 'actionwebservice'Modify the file app/controllers/item_controller.rb
class ItemController < ApplicationController wsdl_service_name 'Item' web_service_api ItemApi web_service_scaffold :invocation if Rails.env == 'development'Modify the file app/controllers/item_api.rb
def add(name, value) Item.create(:name => name, :value => value).id end
def edit(id, name, value) Item.find(id).update_attributes(:name => name, :value => value) end
def fetch(id) @item1=Item.find(id) Item.new(:id => "{@item1.id}", :value => "#{@item1.value}", :name => "#{@item1.name}") end end
class ItemApi < ActionWebService::API::Base
api_method :add, :expects => [:string, :string], :returns => [:int]
api_method :edit, :expects => [:int, :string, :string], :returns => [:bool]
api_method :fetch, :expects => [:int], :returns => [Item]
end
Ok, let's start the service know, and see if we can read the wsdl file
$ ./script/server
$ curl http://localhost:3000/item/wsdl
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="Item" xmlns:typens="urn:ActionWebService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="urn:ActionWebService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:ActionWebService">
<xsd:complexType name="Item">
<xsd:all>
<xsd:element name="id" type="xsd:int"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="value" type="xsd:string"/>
<xsd:element name="created_at" type="xsd:dateTime"/>
<xsd:element name="updated_at" type="xsd:dateTime"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
.......
$ curl http://localhost:3000/item/invocation
...some..nice..readable..html...
So far so good, let's build a Soap Client to use the service via ruby. Create a file test.rb
require 'soap/wsdlDriver'
wsdl = "http://localhost:3000/item/service.wsdl"
item_server = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
item_id = item_server.add('foo', 'bar')
if item_server.edit(item_id, 'John', 'Doe')
puts 'Hey, it worked!'
else
puts 'Back to the drawing board...'
end
# Hey, it worked!
item = item_server.fetch(item_id)
item.class # => SOAP::Mapping::Object
item.name # => "John"
item.value # => "Doe"
If we run this, it will spit out the error “Cannot Map {objType} to SOAP/OM”.
def fetch(id)
@item1=Item.find(id)
Item.new(:id => "{@item1.id}", :value => "#{@item1.value}", :name => "#{@item1.name}")
end
The example now works again. So far, Soap for Rails seems to be working ok.