tags:

views:

458

answers:

3

Assume I have simple XML-RPC service that is implemented with 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 anyone tell me how to call getTest() fuction from C#. Thankyou.

+1  A: 

In order to call the getTest method from c# you will need an XML-RPC client library. XML-RPC is an example of such a library.

Darin Dimitrov
+2  A: 

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.

Matthew Scharley
A: 

Thank you for answer, I try xml-rpc library from darin link. I can call getTest function with 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);
            }
        }
    }
bugbug