7

Python で実装された単純な XML-RPC サービスがあるとします。

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

getTest()C# から関数を呼び出す方法を教えてもらえますか?

4

3 に答える 3

3

回答ありがとうございます。darin link から 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);
            }
        }
    }
于 2009-07-07T08:19:15.917 に答える
3

私自身の角を鳴らしませんが、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());
    }
}

それはうまくいくはずです... 上記のライブラリはLGPLであり、それはあなたにとって十分である場合とそうでない場合があることに注意してください。

于 2009-07-07T07:31:21.397 に答える
2

c#からgetTestメソッドを呼び出すには、XML-RPCクライアントライブラリが必要です。XML-RPCはそのようなライブラリの例です。

于 2009-07-07T07:30:34.143 に答える