2009-07-07 8 views
5

Supongamos que tengo sencilla servicio XML-RPC que se implementa con Python:¿Cómo comunicarse entre Python y C# usando XML-RPC?

from SimpleXMLRPCServer import SimpleXMLRPCServer 

    def getTest(): 
     return 'test message' 

    if __name__ == '__main__' : 
     server = SimpleThreadedXMLRPCServer(('localhost', 8888)) 
     server.register_fuction(getText) 
     server.serve_forever() 

¿Puede alguien decirme cómo llamar a la función getTest() de C#?

Respuesta

2

Para llamar al método getTest desde C#, necesitará una biblioteca cliente XML-RPC. XML-RPC es un ejemplo de dicha biblioteca.

3

Por no Toot mi molino, pero: http://liboxide.svn.sourceforge.net/viewvc/liboxide/trunk/Oxide.Net/Rpc/

class XmlRpcTest : XmlRpcClient 
{ 
    private static Uri remoteHost = new Uri("http://localhost:8888/"); 

    [RpcCall] 
    public string GetTest() 
    { 
     return (string)DoRequest(remoteHost, 
      CreateRequest("getTest", null)); 
    } 
} 

static class Program 
{ 
    static void Main(string[] args) 
    { 
     XmlRpcTest test = new XmlRpcTest(); 
     Console.WriteLine(test.GetTest()); 
    } 
} 

Que debe hacer el truco ... Nota, la biblioteca anterior es LGPL, que pueden o no ser lo suficientemente bueno para usted.

3

Gracias por su respuesta, pruebo la biblioteca xml-rpc del enlace Darin. Puedo llamar a la función getTest con el siguiente código

using CookComputing.XmlRpc; 
... 

    namespace Hello 
    { 
     /* proxy interface */ 
     [XmlRpcUrl("http://localhost:8888")] 
     public interface IStateName : IXmlRpcProxy 
     { 
      [XmlRpcMethod("getTest")] 
      string getTest(); 
     } 

     public partial class Form1 : Form 
     { 
      public Form1() 
      { 
       InitializeComponent(); 
      } 
      private void button1_Click(object sender, EventArgs e) 
      { 
       /* implement section */ 
       IStateName proxy = (IStateName)XmlRpcProxyGen.Create(typeof(IStateName)); 
       string message = proxy.getTest(); 
       MessageBox.Show(message); 
      } 
     } 
    } 
Cuestiones relacionadas