How to communicate between Python and C # using XML-RPC?

Suppose I have a simple XML-RPC service that is implemented using Python:

from SimpleXMLRPCServer import SimpleXMLRPCServer

    def getTest():
        return 'test message'

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

Can someone tell me how to call the getTest () function from C #?

+5
source share
3 answers

Do not use your own horn, but: 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());
    }
}

This should do the trick ... Please note: the above LGPL library, which may or may not be good enough for you.

+3
source

Thanks for the answer, I will try the xml-rpc library from the darin link. I can call the getTest function with the following code

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);
            }
        }
    }
+3
source

getTest # XML-RPC. XML-RPC .

+2

All Articles