我正在使用库xml-rpc.net.2.5.0用于在 C# 中创建调用一些 python 方法的 XML RPC 客户端。客户端位于Windows7机器中,服务器位于运行red hat的VMWare中。
调用python函数的客户端代码(main方法内的代码):
IRemoteKillTest iRemoteKillTest = XmlRpcProxyGen.Create<IRemoteKillTest>();
int result = iRemoteKillTest.kill();
Console.WriteLine("Result = " + result);
Console.ReadLine();
客户端界面:
[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();
}
服务器代码:
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()
如果客户端调用函数msg从 python 中它执行成功并且字符串返回到 c# 但如果它调用函数kill我得到以下异常:
XmlRpcFaultException:
Server returned a fault exception: [1] exceptions.Exception:method "kill" is not supported
对于任何其他 python 方法,如 os.listdir、subprocess.Popen 等,都会发生这种情况。
我已经进行了测试调用kill方法来自在 VMWare red hat 内运行的 python 客户端,并且它可以工作。
我需要尽快获得帮助,所以如果有人已经遇到过这个问题并对此做出解释,这将非常有用。
预先感谢并致以问候,