XML RPC - calling python functions from C #

I am using lib xml-rpc.net.2.5.0 to create an XML RPC client in C # that calls some python methods. The client is on a Windows7 machine, and the server is on VMWare, working with a red hat.

Client code that calls the python function (code inside the 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 the msg function from python, it is successful and the string is returned in C #, but if it calls the kill function , I got the following exception:

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

python, os.listdir, subprocess.Popen .. , python, VMWare, .

, PLS, - , , . ,

+4

Source: https://habr.com/ru/post/1533628/


All Articles