XMLRPC c# 客户端到 python 客户端 - 方法不存在
我在网上搜索并看到以下问题: XML-RPC C# 和 Python RPC 服务器
我尝试了一段时间做同样的事情,但失败了。我收到异常“不支持方法“HelloWorld”...”
[XmlRpcUrl("http://192.168.0.xxx:8000/RPC2")]
public interface HelloWorld : IXmlRpcProxy
{
[XmlRpcMethod]
String HelloWorld();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
HelloWorld proxy = CookComputing.XmlRpc.XmlRpcProxyGen.Create<HelloWorld>();
textBox1.Text = proxy.HelloWorld();
}
catch (Exception ex)
{
HandleException(ex);
}
}
并且我的 Python 服务器是:
class LGERequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
def HelloWorld():
return "This is server..."
server = SimpleXMLRPCServer(("192.168.0.xxx", 8000),
requestHandler=LGERequestHandler)
server.register_introspection_functions()
server.register_function("HelloWorld", HelloWorld)
server.register_instance(self)
# Run the server's main loop
server.serve_forever()
服务器已启动并正在运行,但我仍然收到异常。
I've searched the web and seen the following question: XML-RPC C# and Python RPC Server
I'm trying for a while to do the same, but I fail. I get the exception "Method "HelloWorld" is not supported..."
[XmlRpcUrl("http://192.168.0.xxx:8000/RPC2")]
public interface HelloWorld : IXmlRpcProxy
{
[XmlRpcMethod]
String HelloWorld();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
HelloWorld proxy = CookComputing.XmlRpc.XmlRpcProxyGen.Create<HelloWorld>();
textBox1.Text = proxy.HelloWorld();
}
catch (Exception ex)
{
HandleException(ex);
}
}
And my Python server is:
class LGERequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
def HelloWorld():
return "This is server..."
server = SimpleXMLRPCServer(("192.168.0.xxx", 8000),
requestHandler=LGERequestHandler)
server.register_introspection_functions()
server.register_function("HelloWorld", HelloWorld)
server.register_instance(self)
# Run the server's main loop
server.serve_forever()
The server is up and running, but I still get an exception.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题:
语法问题
server.register_function("HelloWorld", HelloWorld)
应该是server.register_function(HelloWorld, "HelloWorld")
。这个更改也不起作用,所以我将函数名称形式
helloWorld
更改为hello
并且它起作用了(!)I found the problem:
Syntax problem
server.register_function("HelloWorld", HelloWorld)
should beserver.register_function(HelloWorld, "HelloWorld")
.This change also didn't work, so I changed the function name form
helloWorld
tohello
and it worked(!)