Forum: Ruby on Rails Trouble connecting to a Rails SOAP web service with a simple

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peter M. (Guest)
on 2006-02-20 03:25
(Received via mailing list)
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
Peter M. (Guest)
on 2006-02-20 03:29
(Received via mailing list)
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/">
      <param0 xsi:type="xsd:int">1</param0>
    </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/">
      <return xsi:type="n1:Product">
        <id xsi:type="xsd:int">1</id>
        <name xsi:type="xsd:string">gamma</name>
        <description xsi:type="xsd:string">An all time
classic.</description>
      </return>
    </n1:FindProductByIdResponse>
  </env:Body>
</env:Envelope>
Peter M. (Guest)
on 2006-02-20 05:41
(Received via mailing list)
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
Peter M. (Guest)
on 2006-02-20 17:48
(Received via mailing list)
I've been fighting with this for hours. What's going on?
This topic is locked and can not be replied to.