Rails ActionWebservice called using /api error

Dear RoR experts,

I have trouble calling RoR ActionWebservice without the Invoke
Scaffolding. I’d no problem testing the webservice using Invoke
Scaffolding. I’ve used the SOAP n XML-RPC and no problem geting the
results. I’m currently using Delegated despatch mode (coz i want to
access this service through third-party easily) but when i called the
web service using “http://localhost:3000/calc/api” this is what my app
log (log/development.log) and my web browser returned :


Processing CalcController#api (for 127.0.0.1 at 2006-08-23 15:16:20)
[GET]
Session ID: edce479c8c82f9c91a3f9d295897b4c5
Parameters: {“action”=>“api”, “controller”=>“calc”}

RuntimeError (NilClass is not a valid input stream. It must be
either a String, IO, StringIO or Source.):
/usr/local/lib/ruby/1.8/rexml/parsers/baseparser.rb:133:in stream=' /usr/local/lib/ruby/1.8/rexml/parsers/baseparser.rb:100:in initialize’
/usr/local/lib/ruby/1.8/rexml/parsers/streamparser.rb:6:in initialize' /usr/local/lib/ruby/1.8/rexml/document.rb:173:in parse_stream’
/usr/local/lib/ruby/1.8/xmlrpc/parser.rb:717:in parse' /usr/local/lib/ruby/1.8/xmlrpc/parser.rb:475:in parseMethodCall’
/usr/local/lib/ruby/1.8/xmlrpc/marshal.rb:63:in load_call' /usr/local/lib/ruby/1.8/xmlrpc/marshal.rb:32:in load_call’
/usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.1.2/lib/action_web_ser
vice/protocol/xmlrpc_protocol.rb:36:in
decode_request' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.1.2/lib/action_web_ser vice/protocol/xmlrpc_protocol.rb:32:in decode_action_pack_request’
/usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.1.2/lib/action_web_ser
vice/protocol/discovery.rb:20:in
discover_web_service_request' /usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.1.2/lib/action_web_ser vice/protocol/discovery.rb:18:in discover_web_service_request’
/usr/local/lib/ruby/gems/1.8/gems/actionwebservice-1.1.2/lib/action_web_ser
vice/dispatcher/action_controller_dispatcher.rb:44:in
dispatch_web_service_request' (eval):1:in api’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
ase.rb:910:in
perform_action_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/f ilters.rb:368:in perform_action_without_benchmark’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
enchmarking.rb:69:in
perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in measure’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
enchmarking.rb:69:in
perform_action_without_rescue' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/r escue.rb:82:in perform_action’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
ase.rb:381:in
process_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/f ilters.rb:377:in process_without_session_management_support’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/s
ession_management.rb:117:in
process' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in dispatch’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:115:in
handle_dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:81:in service’
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in run’
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in start_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in start’
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in start’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:67:in
dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2 /lib/commands/servers/webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in require’
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/de
pendencies.rb:147:in
require' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/server.rb:30 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in require’
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/de
pendencies.rb:147:in
`require’
./script/server:3

Completed in 0.00908 (110 reqs/sec) | 500 Internal Protocol Error [
http://localhost/calc/api]

Here are my source codes :

[[ api/calc_api.rb ]]

class CalcApi < ActionWebService::API::Base
api_method :add,
:expects => [:int,:int],
:returns => [:int]
end

[[ controllers/calc_controller.rb ]]

class CalcController < ApplicationController
web_service_dispatching_mode :delegated
web_service :calcservice2, CalcService.new
web_service_scaffold :invoke

end

[[ models/calc_service.rb ]]

class CalcService < ActionWebService::Base
web_service_api CalcApi
def add (a,b)
return a+b
end
end

N can anybody help me how to call RoR webservice from .NET / Java / PHP
client ?

Thank you

Amri H.

hi amri,
just try running your server at 3000 and your client code from a
server
running at 3001 i mean run two webrick servers
1-for server on which web service is there
2-for the client application which will try accessing this service

if it works then your code is correct

few weeks back i had same problem it worked this way problem is with
webrick
i suppose it cannot act as both server and client for webservice at
sametime on localhost it runs into a loop.

just try this if it helps

Dear Gaurav Bagga,

Thank you 4 your reply :smiley:

The problem is i was ran it as a service (as a webservice) n no other
rails application (webrick) was running.

cheers,

Amri,

You can’t call a web service using HTTP GET method. Both SOAP and
XML-RPC protocols expect a xml request which you must send as a
payload of HTTP POST request.

On 8/23/06, Amri H. [email protected] wrote:

/usr/local/lib/ruby/1.8/rexml/parsers/streamparser.rb:6:in initialize' decode_action_pack_request’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
enchmarking.rb:69:in
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/s
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread' require’

:expects => [:int,:int],

end


Kent

Dear Kent,

Thank you very much … now i get it :smiley: thanx again.

My problem now is that i cant see whether my RoR Webservice being
called/not. My program (ActiveBPEL designer) told me that it couldn’t
connected to my RoR webservie. I have my RoR Webservice WSDL generated
by Rails. So i just insert it to my ActiveBPEL designer.

I dunno how ActiveBPEL works with my WSDL but i assumed it works fine.
I’ll also ask this same question to ActiveBPEL forum.

Thank you.