Forum: Ruby on Rails WebService XML-RPC session access?

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.
Nate (Guest)
on 2007-01-16 23:17
(Received via mailing list)
Is there a way to provide access to the session[] from an XML-RPC
server?

I am currently writing an XML-RPC server in Rails, and am using layered
dispatching. Unfortunately, everything works great except session is
always null in the ActionWebService controllers.

Is it possible to get session[] working with layered dispatch in
ActionWebService?

Thanks,
Nate
Nate (Guest)
on 2007-01-17 00:16
(Received via mailing list)
In case anyone else spends a WEEK trying to get XML-RPC sessions
working like I did.

I combined another post in this Google group about HTTP authentication
with my approach. This uses 401 Basic authentication, and returns a
session_id which can be passed as a Cookie in subsequent requests. Not
completely XMLRPC stds-compliant, but works for Rails/Perl/Java.

The missing link was I have to call new(session) in my layered
dispatcher:

   class RpcController < ApplicationController
     wsdl_service_name 'RPC'
     web_service_dispatching_mode :layered

     # Must use the {BLOCK} mode of layered dispatch, and explicitly
     # pass the session ID into the new() method
     web_service(:auth) { AuthService.new(session) }
   end

Then, in apis/auth_service.rb:

   class AuthService < XmlRpcService
     web_service_api AuthAPI
     # methods here...
   end

And finally, my base XMLRPC ActionWebService class,
apis/xml_rpc_service.rb:

  class XmlRpcService < ApplicationController
    def initialize(session)
       logger.debug "new=#{session}"
       @session = session
    end
  end

I setup all my layered WebService classes to inherit from this.

Just had to find the right combination of black magic...

-Nate
This topic is locked and can not be replied to.