簡體   English   中英

XML-RPC C#和Python RPC服務器

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

在我的服務器上,我使用Python的標准示例(使用額外的Hello World方法),在客戶端,我使用C#中的XML-RPC.NET庫。 但每次我運行我的客戶端時,我都會得到一個異常,即找不到該方法。 任何想法如何解決。

謝謝!

蟒蛇:

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

如果您將聲明更改為此可行嗎?

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

Python文檔

SimpleXMLRPCRequestHandler.rpc_paths

一個屬性值,必須是一個元組,列出用於接收XML-RPC請求的URL的有效路徑部分。 發布到其他路徑的請求將導致404“無此頁面”HTTP錯誤。 如果此元組為空,則所有路徑都將被視為有效。 默認值為('/','/ RPC2')。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM