4

I am using lib xml-rpc.net.2.5.0 for creating a XML RPC client in C# which invokes some python methods. The client is located in a Windows7 machine and the server is located in VMWare running red hat.

Client code which invokes python function (code inside main method):

IRemoteKillTest iRemoteKillTest = XmlRpcProxyGen.Create<IRemoteKillTest>();

int result = iRemoteKillTest.kill();
Console.WriteLine("Result = " + result);
Console.ReadLine();

Client Interface:

[XmlRpcUrl("http://192.ZZZ.YYY.XXX:8000/RPC2")]
public interface IRemoteKillTest : IXmlRpcProxy
{
    [XmlRpcMethod]
    int kill();
}

[XmlRpcUrl("http://192.ZZZ.YYY.XXX:8000/RPC2")]
public interface IRemoteMsgTest : IXmlRpcProxy
{
    [XmlRpcMethod]
    string msg();
}

Server code:

from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
import subprocess

class RequestHandler(SimpleXMLRPCRequestHandler):
       rpc_paths = ('/RPC2',)

server = SimpleXMLRPCServer(("192.ZZZ.YYY.XXX", 8000), requestHandler=RequestHandler)
server.register_introspection_functions()

class MyFuncs:
    def msg(self):
        return "It Works!"

    def kill(self):
        status = subprocess.call("ps -ef | grep <my_grep_info>  | grep -v grep | awk  '{ print $2 }' | xargs kill", shell=True)
        return status

 server.register_instance(MyFuncs())
 server.serve_forever()

If the client calls function msg from python it is executed successfully and the string is returned to c# but if it calls function kill i got the following exception:

XmlRpcFaultException:
Server returned a fault exception: [1] exceptions.Exception:method "kill" is not supported

It happens for any other python method like os.listdir, subprocess.Popen and so on. I have made a test calling kill method from a python client running inside VMWare red hat and it works.

I need a help as soon as possible, so pls if anyone has already faced it and have a explanation for that it will be very usefull. Thanks in advance and regards,

user2475117
  • 43
  • 1
  • 5
  • I forgot to say but i have already tried the solution in discussion: http://stackoverflow.com/questions/7124937/xmlrpc-c-sharp-client-to-python-client-method-does-not-exists?rq=1 – user2475117 Mar 26 '14 at 23:05
  • I don´t have reputation for answering my own question, follows a short description. In order to fix this problem we need or break command down or pass a shell=True as args. Ex: subprocess.call(["ls", "-la"]) or subprocess.call("ls -la", shell=True) The first example is the best one because you disable some features from shell but it does not affect its execution and the second one are discouraged by python documentation for security reasons. Most of my methods does not use shell arg or command broken down that´s why it was not working. – user2475117 Mar 27 '14 at 05:28

0 Answers0