Assume I have simple XML-RPC service that is implemented with Python:
假设我有使用Python实现的简单XML-RPC服务:
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() function from C#?
谁能告诉我如何从C#调用getTest()函数?
3 个解决方案
#1
Not to toot my own horn, but: http://liboxide.svn.sourceforge.net/viewvc/liboxide/trunk/Oxide.Net/Rpc/
不要自言自语,但是: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.
这应该是诀窍......注意,上面的库是LGPL,它可能或可能不够好。
#2
Thank you for answer, I try xml-rpc library from darin link. I can call getTest function with following code
谢谢你的回答,我从darin链接尝试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);
}
}
}
#3
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.
为了从c#调用getTest方法,您需要一个XML-RPC客户端库。 XML-RPC就是这种库的一个例子。
#1
Not to toot my own horn, but: http://liboxide.svn.sourceforge.net/viewvc/liboxide/trunk/Oxide.Net/Rpc/
不要自言自语,但是: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.
这应该是诀窍......注意,上面的库是LGPL,它可能或可能不够好。
#2
Thank you for answer, I try xml-rpc library from darin link. I can call getTest function with following code
谢谢你的回答,我从darin链接尝试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);
}
}
}
#3
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.
为了从c#调用getTest方法,您需要一个XML-RPC客户端库。 XML-RPC就是这种库的一个例子。