# WebService XML-RPC session access?

**URL:** <https://www.ruby-forum.com/t/webservice-xml-rpc-session-access/82018>\
**Category:** Rails\
**Created:** [January 16, 2007, 10:17pm UTC](https://www.ruby-forum.com/t/webservice-xml-rpc-session-access/82018 "2007-01-16T22:17:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [January 16, 2007, 10:17pm UTC](https://www.ruby-forum.com/t/webservice-xml-rpc-session-access/82018/1 "2007-01-16T22:17:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [January 16, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/webservice-xml-rpc-session-access/82018/2 "2007-01-16T23:16:58Z")

</div>

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
