XMLRPC c# 客户端到 python 客户端 - 方法不存在

发布于 2024-11-30 14:31:46 字数 1141 浏览 5 评论 0原文

我在网上搜索并看到以下问题: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东风软 2024-12-07 14:31:46

我发现了问题:

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

  2. 这个更改也不起作用,所以我将函数名称形式 helloWorld 更改为 hello 并且它起作用了(!)

I found the problem:

  1. Syntax problem server.register_function("HelloWorld", HelloWorld) should be server.register_function(HelloWorld, "HelloWorld").

  2. This change also didn't work, so I changed the function name form helloWorld to hello and it worked(!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文