2009-10-17 57 views
5

Na moim serwerze używam standardowego przykładu dla Pythona (z dodatkowym sposobem Hello World) i po stronie klienta używam biblioteki XML-RPC.NET w C# . Ale za każdym razem, gdy uruchomię mojego klienta, otrzymuję wyjątek, że metoda nie zostanie znaleziona. Wszelkie pomysły, jak to naprawić.XML-RPC C# i Python RPC Server

dziękuję!

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

Opublikowanie wyjątku, w tym stosu, może być pomocne ... –

Odpowiedz

5

Czy to działa w przypadku zmiany oświadczenia w tej kwestii?

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

Z Python docs:

SimpleXMLRPCRequestHandler.rpc_paths

wartość atrybutu, który musi być krotką Lista ważnych części ścieżkę URL do odbierania żądań XML-RPC. Żądania wysłane do innych ścieżek spowodują błąd HTTP 404 "brak takiej strony". Jeśli ta krotka jest pusta, wszystkie ścieżki będą uznane za prawidłowe. Domyślna wartość to ('/', '/ RPC2').

+0

Świetne. To działa! –