7

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#?

John Y
  • 14,123
  • 2
  • 48
  • 72
wearetherock
  • 3,721
  • 8
  • 36
  • 47

3 Answers3

3

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
  • 127,823
  • 52
  • 194
  • 222
3

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);
            }
        }
    }
wearetherock
  • 3,721
  • 8
  • 36
  • 47
1

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
  • 1,023,142
  • 271
  • 3,287
  • 2,928