Trouble connecting to a Rails SOAP web service with a simple

Hi,

The code for my Rails webservice is below. It working just fine
through the Rails web service scaffold invoke

http://localhost:3000/ProductBackend/invoke

I’m trying to write a plain ruby command line client to access the
webservice.

require ‘soap/rpc/driver’
proxy = SOAP::RPC::Driver.new(“http://localhost:3000/product_backend”,
“urn:ActionWebService”)
proxy.add_method(‘find_product_by_id’, ‘id’)
puts “Product: #{proxy.find_product_by_id(2).name}”

I also tried http://localhost:3000/ProductBackend

I see the following

$ ruby client.rb
/usr/local/lib/ruby/1.8/soap/streamHandler.rb:270:in send_post': 404: Not Found (SOAP::HTTPStreamError) from /usr/local/lib/ruby/1.8/soap/streamHandler.rb:103:in send’
from /usr/local/lib/ruby/1.8/soap/rpc/proxy.rb:114:in invoke' from /usr/local/lib/ruby/1.8/soap/rpc/proxy.rb:131:in call’
from /usr/local/lib/ruby/1.8/soap/rpc/driver.rb:275:in call' from /usr/local/lib/ruby/1.8/soap/rpc/driver.rb:302:in find_product_by_id’
from /usr/local/lib/ruby/1.8/soap/rpc/driver.rb:297:in
`find_product_by_id’
from client.rb:4

What’s wrong?

Thanks,
Peter

############## app/controllers/product_backend_controller.rb
##############

class ProductBackendController < ApplicationController
wsdl_service_name ‘ProductBackend’
web_service_api ProductBackendApi
web_service_scaffold :invoke

def find_product_by_id(id)
Product.find(id)
end
end

############## app/apis/product_backend_api.rb ##############

class ProductBackendApi < ActionWebService::API::Base
api_method :find_product_by_id,
:expects => [:int],
:returns => [Product]
end

In case it helps here are the XML request and responses

Request XML:

<?xml version="1.0" encoding="utf-8" ?>

<env:Envelope xmlns:xsd=“http://www.w3.org/2001/XMLSchema
xmlns:env=“http://schemas.xmlsoap.org/soap/envelope/
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
env:Body
<n1:FindProductById xmlns:n1=“urn:ActionWebService”
env:encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/”>
1
</n1:FindProductById>
</env:Body>
</env:Envelope>

Response XML:

<?xml version="1.0" encoding="UTF-8" ?>

<env:Envelope xmlns:xsd=“http://www.w3.org/2001/XMLSchema
xmlns:env=“http://schemas.xmlsoap.org/soap/envelope/
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
env:Body
<n1:FindProductByIdResponse xmlns:n1=“urn:ActionWebService”
env:encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/”>

1
gamma
An all time
classic.

</n1:FindProductByIdResponse>
</env:Body>
</env:Envelope>

I found out a little more but still am getting an error.

My client

require ‘soap/rpc/driver’
proxy =
SOAP::RPC::Driver.new(“http://localhost:3000/ProductBackend/api”,
“urn:ActionWebService”)
proxy.add_method(‘find_product_by_id’)
puts “Product: #{proxy.find_product_by_id(2).name}”

Produces

$ ruby client.rb
/usr/local/lib/ruby/1.8/soap/rpc/driver.rb:300:in
find_product_by_id': wrong number of arguments (1 for 0) (ArgumentError) from /usr/local/lib/ruby/1.8/soap/rpc/driver.rb:297:in find_product_by_id’
from client.rb:6

and if I remove the 2 in the call to proxy.find_product_by_id so there
are no arguments (which is wrong, of course)

$ ruby client.rb
/usr/local/lib/ruby/1.8/soap/rpc/proxy.rb:132:in call': undefined method header’ for nil:NilClass (NoMethodError)
from /usr/local/lib/ruby/1.8/soap/rpc/driver.rb:275:in call' from /usr/local/lib/ruby/1.8/soap/rpc/driver.rb:302:in find_product_by_id’
from /usr/local/lib/ruby/1.8/soap/rpc/driver.rb:297:in
`find_product_by_id’
from client.rb:6

I’ve been fighting with this for hours. What’s going on?