2009-07-07 22 views
5

Si supponga che ho semplice servizio di XML-RPC che viene implementato con Python:Come comunicare tra Python e 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() 

Qualcuno può dirmi come chiamare la funzione getTest() da C#?

risposta

2

Per chiamare il metodo getTest da C# è necessaria una libreria client XML-RPC. XML-RPC è un esempio di tale libreria.

3

Non a toot il mio proprio corno, ma: 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()); 
    } 
} 

Questo dovrebbe fare il trucco ... Nota, la libreria sopra è LGPL, che può o non può essere abbastanza buono per voi.

3

Grazie per la risposta, provo la libreria xml-rpc dal collegamento di Darin. Posso chiamare la funzione getTest con il seguente codice

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); 
      } 
     } 
    } 
Problemi correlati