【问题标题】:XML-RPC C# and Python RPC ServerXML-RPC C# 和 Python RPC 服务器
【发布时间】:2010-12-07 16:03:15
【问题描述】:

在我的服务器上,我使用 Python 的标准示例(带有额外的 Hello World 方法),而在客户端,我使用 C# 中的 XML-RPC.NET 库。 但是每次我运行我的客户端时,我都会收到找不到该方法的异常。任何想法如何解决这个问题。

谢谢!

Python:

from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler

# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/RPC2',)

# Create server
server = SimpleXMLRPCServer(("", 8000),
                            requestHandler=RequestHandler)
server.register_introspection_functions()

# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(pow)

# Register a function under a different name
def adder_function(x,y):
    return x + y
server.register_function(adder_function, 'add')

def HelloWorld():
        return "Hello Henrik"

server.register_function(HelloWorld,'HelloWorld')

# Register an instance; all the methods of the instance are
# published as XML-RPC methods (in this case, just 'div').
class MyFuncs:
    def div(self, x, y):
        return x // y

server.register_instance(MyFuncs())

# Run the server's main loop
server.serve_forever()

C#

namespace XMLRPC_Test
{
    [XmlRpcUrl("http://188.40.xxx.xxx:8000")]
    public interface HelloWorld : IXmlRpcProxy
    {
        [XmlRpcMethod]
        String HelloWorld();
    }
    [XmlRpcUrl("http://188.40.xxx.xxx:8000")]
    public interface add : IXmlRpcProxy
    {
        [XmlRpcMethod]
        int add(int x, int y);
    } 
    [XmlRpcUrl("http://188.40.xxx.xxx:8000")]
    public interface listMethods : IXmlRpcProxy
    {
        [XmlRpcMethod("system.listMethods")]  
        String listMethods();
    } 

    class Program
    {
        static void Main(string[] args)
        {
            listMethods proxy = XmlRpcProxyGen.Create<listMethods>();
            Console.WriteLine(proxy.listMethods());
            Console.ReadLine();
        }
    }
}

【问题讨论】:

  • 发布你得到的异常,包括堆栈跟踪,可能会有所帮助......

标签: c# python xml-rpc


【解决方案1】:

如果你把声明改成这样行吗?

[XmlRpcUrl("http://188.40.xxx.xxx:8000/RPC2")]

来自Python docs

SimpleXMLRPCRequestHandler.rpc_paths

一个属性值,它必须是一个元组,列出用于接收 XML-RPC 请求的 URL 的有效路径部分。发布到其他路径的请求将导致 404“没有此类页面”HTTP 错误。如果此元组为空,则所有路径都将被视为有效。默认值为 ('/', '/RPC2')。

【讨论】:

    猜你喜欢
    • 2012-01-14
    • 2016-01-05
    • 2015-09-11
    • 2011-04-23
    • 1970-01-01
    • 2011-04-18
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    相关资源
    最近更新 更多