Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

c#

xml-rpc

Assume I have a simple XML-RPC service that is implemented with Python:

from SimpleXMLRPCServer import SimpleXMLRPCServer  # Python 2

def getTest():
    return 'test message'

if __name__ == '__main__' :
    server = SimpleXMLRPCServer(('localhost', 8888))
    server.register_function(getTest)
    server.serve_forever()

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

like image 202
wearetherock Avatar asked Jul 07 '09 07:07

wearetherock


People also ask

Can we use python and c together?

Any code that you write using any compiled language like C, C++, or Java can be integrated or imported into another Python script. This code is considered as an "extension."

Can C# talk to python?

Calling Python from C# is easily possible via Pyrolite where your Python code is running as a Pyro4 server. It should be fast enough to handle "large arrays of numbers" however you didn't specify any performance constraints.


1 Answers

Not to toot my 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());
    }
}

That should do the trick... Note, the above library is LGPL, which may or may not be good enough for you.

like image 185
Matthew Scharley Avatar answered Oct 12 '22 13:10

Matthew Scharley