简体   繁体   English

XML-RPC C#和Python RPC服务器

[英]XML-RPC C# and Python RPC Server

On my server, I'm using the standard example for Python (with an extra Hello World Method) and on the Client side I'm using the XML-RPC.NET Library in C#. 在我的服务器上,我使用Python的标准示例(使用额外的Hello World方法),在客户端,我使用C#中的XML-RPC.NET库。 But everytime I run my client I get the exception that the method is not found. 但每次我运行我的客户端时,我都会得到一个异常,即找不到该方法。 Any Ideas how fix that. 任何想法如何解决。

thanks! 谢谢!

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# 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();
        }
    }
}

Does it work if you change the declaration to this? 如果您将声明更改为此可行吗?

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

From the Python docs : Python文档

SimpleXMLRPCRequestHandler.rpc_paths

An attribute value that must be a tuple listing valid path portions of the URL for receiving XML-RPC requests. 一个属性值,必须是一个元组,列出用于接收XML-RPC请求的URL的有效路径部分。 Requests posted to other paths will result in a 404 “no such page” HTTP error. 发布到其他路径的请求将导致404“无此页面”HTTP错误。 If this tuple is empty, all paths will be considered valid. 如果此元组为空,则所有路径都将被视为有效。 The default value is ('/', '/RPC2'). 默认值为('/','/ RPC2')。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM