2009-10-17 108 views
5

在我的服務器上,我使用Python的標準示例(帶有額外的Hello World方法),在客戶端,我在C#中使用XML-RPC.NET庫。 但是每次運行我的客戶端時,我都會得到該方法未找到的異常。任何想法如何修復。XML-RPC C#和Python RPC服務器

謝謝!

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

發佈你得到的例外,包括堆棧跟蹤,可能會有幫助... – 2009-10-17 19:46:48

回答

5

請問如果更改聲明這個工作?

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

Python docs

SimpleXMLRPCRequestHandler.rpc_paths

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

+0

很好。有用! – 2009-10-17 19:48:48