# Trouble connecting to a Rails SOAP web service with a simple

**URL:** <https://www.ruby-forum.com/t/trouble-connecting-to-a-rails-soap-web-service-with-a-simple/70687>\
**Category:** Rails\
**Created:** [February 20, 2006, 2:25am UTC](https://www.ruby-forum.com/t/trouble-connecting-to-a-rails-soap-web-service-with-a-simple/70687 "2006-02-20T02:25:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [February 20, 2006, 2:25am UTC](https://www.ruby-forum.com/t/trouble-connecting-to-a-rails-soap-web-service-with-a-simple/70687/1 "2006-02-20T02:25:59Z")

</div>

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](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](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](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

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [February 20, 2006, 2:29am UTC](https://www.ruby-forum.com/t/trouble-connecting-to-a-rails-soap-web-service-with-a-simple/70687/2 "2006-02-20T02:29:01Z")

</div>

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](http://www.w3.org/2001/XMLSchema)”  
xmlns:env=“[http://schemas.xmlsoap.org/soap/envelope/](http://schemas.xmlsoap.org/soap/envelope/)”  
xmlns:xsi=“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”\>  
env:Body  
\<n1:FindProductById xmlns:n1=“urn:ActionWebService”  
env:encodingStyle=“[http://schemas.xmlsoap.org/soap/encoding/](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](http://www.w3.org/2001/XMLSchema)”  
xmlns:env=“[http://schemas.xmlsoap.org/soap/envelope/](http://schemas.xmlsoap.org/soap/envelope/)”  
xmlns:xsi=“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”\>  
env:Body  
\<n1:FindProductByIdResponse xmlns:n1=“urn:ActionWebService”  
env:encodingStyle=“[http://schemas.xmlsoap.org/soap/encoding/](http://schemas.xmlsoap.org/soap/encoding/)”\>  
  
1  
gamma  
An all time  
classic.  
  
\</n1:FindProductByIdResponse\>  
\</env:Body\>  
\</env:Envelope\>

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [February 20, 2006, 4:41am UTC](https://www.ruby-forum.com/t/trouble-connecting-to-a-rails-soap-web-service-with-a-simple/70687/3 "2006-02-20T04:41:54Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [February 20, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/trouble-connecting-to-a-rails-soap-web-service-with-a-simple/70687/4 "2006-02-20T16:48:29Z")

</div>

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