首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XML-RPC C#和Python RPC Server

XML-RPC C#和Python RPC Server
EN

Stack Overflow用户
提问于 2009-10-17 19:29:52
回答 1查看 3.2K关注 0票数 5

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

谢谢!

Python:

代码语言:javascript
复制
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#

代码语言:javascript
复制
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();
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-10-17 19:47:09

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

代码语言:javascript
复制
[XmlRpcUrl("http://188.40.xxx.xxx:8000/RPC2")]

Python docs

SimpleXMLRPCRequestHandler.rpc_paths

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

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1583017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档