2009-07-07 104 views
5

假設我有一個與Python實現簡單的XML-RPC服務:如何使用XML-RPC在Python和C#之間進行通信?

from SimpleXMLRPCServer import SimpleXMLRPCServer 

    def getTest(): 
     return 'test message' 

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

誰能告訴我如何調用getTest()從C#功能?

回答

2

爲了調用從C#中getTest方法,您將需要一個XML-RPC客戶端庫。 XML-RPC就是這樣一個圖書館的例子。

3

不嘟我自己的號角,但: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()); 
    } 
} 

這應該做的伎倆......注意,上面的庫是LGPL,這可能是也可能不是配不上你。

3

謝謝你的回答,我試試darin鏈接的xml-rpc庫。我可以打電話給getTest功能與下面的代碼

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); 
      } 
     } 
    } 
相關問題