1

I have a XMLRPC server running:

#!/usr/bin/env python

from SimpleXMLRPCServer import SimpleXMLRPCServer
import subprocess
import os


def testls():
    retcode=subprocess.call(["ls", "/etc"])
    return retcode



server = SimpleXMLRPCServer(('192.168.15.20',8888),logRequests=True)

server.register_function(testls)

server.register_introspection_functions()
try:
    server.serve_forever()
finally:
    server.server_close()

I need to be able to call it from a ruby client. From what I have found. it seems that it should be this:

require xmlrpc/client
server = XMLRPC::Client.new2("http://192.168.15.20:8888/")

But it returns the following, which suggests that it is not able to reach the service.

=> #<XMLRPC::Client:0x2ab0f5caacf8 @parser=nil, @timeout=30, @path="/", @password=nil, @http_header_extra=nil, @use_ssl=false, @host="192.168.15.20", @user=nil, @proxy_port=nil, @auth=nil, @cookie=nil, @create=nil, @port=8888, @http=#<Net::HTTP 192.168.15.20:8888 open=false>, @proxy_host=nil, @http_last_response=nil>

I had better success with the following, but I was not able to invoke the method:

irb(main):069:0> server = XMLRPC::Client::Proxy.new("http://192.168.15.20","8888")
=> #<XMLRPC::Client::Proxy:0x2ab0f5c4ef48 @args=[], @server="http://192.168.15.20", @meth=:call, @prefix="8888.">
irb(main):070:0> s = server.call('system.listMethods')
NoMethodError: undefined method `call' for "http://192.168.15.20":String
        from /usr/lib/ruby/1.8/xmlrpc/client.rb:608:in `send'
        from /usr/lib/ruby/1.8/xmlrpc/client.rb:608:in `method_missing'
        from (irb):70
        from :0

What is the appropriate code to invoke a call from Ruby to a Python XML-RPC Server?

2 Answers 2

1

I know this is a rather old question, but since it doesn't have a selected answer, I thought I'd share my insights:

In ruby, the class XMLRPC::Client represents a lower level interface to the server:

server = XMLRPC::Client.new( "192.168.15.20", 8888 )
server.call 'system.listMethods'

The class XMLRPC::Client::Proxy is a higher level interface to (parts of) the server that allows for a more natural server method invocation:

system = server.proxy('system')
system.listMethods

Similarly, to access the server's 'root' methods (like those registered via register_function in Python):

main = server.proxy
main.testls
Sign up to request clarification or add additional context in comments.

Comments

0

I'm not familiar with xmlrpc in Ruby, but I think you have to pass an XMLRPC::Client Object to XMLRPC::Client::Proxy. Try stuff like this:

client = XMLRPC::Client.new( "http://192.168.15.20", 8888 )
server = XMLRPC::Client::Proxy.new( client, 8888 )
server.call "system.listMethods"

Maybe it works this way.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.