2009-07-07 4 views
5

Python으로 구현 된 간단한 XML-RPC 서비스가 있다고 가정합니다.파이썬과 C# 사이에서 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() 

누구나 C#에서 getTest() 함수를 호출하는 방법을 알려 줄 수 있습니까?

답변

2

C#에서 getTest 메소드를 호출하려면 XML-RPC 클라이언트 라이브러리가 필요합니다. XML-RPC은 이러한 라이브러리의 예입니다.

3

내 자신의 나팔을 불다,하지만하지 않기 : 트릭 ... 참고해야

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

http://liboxide.svn.sourceforge.net/viewvc/liboxide/trunk/Oxide.Net/Rpc/은, 위의 라이브러리 또는 당신을 위해 충분하지 않을 수 있습니다 LGPL입니다.

3

해피 링크에서 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); 
      } 
     } 
    } 
관련 문제