【问题标题】:XMLRPC c# client to python client - method does not existsXMLRPC c#客户端到python客户端-方法不存在
【发布时间】:2011-10-30 19:06:27
【问题描述】:

我在网上搜索并看到以下问题:XML-RPC C# and Python RPC Server

我尝试了一段时间来做同样的事情,但我失败了。我收到异常“不支持方法“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()

服务器已启动并正在运行,但我仍然遇到异常。

【问题讨论】:

  • 这不是有效的python,缩进与缩进不匹配。请编辑您的答案以反映您遇到问题的实际代码。 (提示:将代码粘贴到编辑框中,选择整个块,然后单击{} 按钮以正确显示缩进)
  • 看起来 C# 客户端没有考虑将方法设为“HelloWorld”。也许如果你将它注册为“HelloWorld.HelloWorld”,或者类似的东西。

标签: c# python xml-rpc simplexmlrpcserver


【解决方案1】:

我发现了问题:

  1. 语法问题server.register_function("HelloWorld", HelloWorld)应该是server.register_function(HelloWorld, "HelloWorld")

  2. 这个更改也没有奏效,所以我将函数名从helloWorld 更改为hello,它奏效了(!)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多