// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Linq; using CookComputing.XmlRpc; namespace Test.Client { public class Data { public int ival { get; set; } public string sval { get; set; } public override string ToString() { return string.Format("({0},{1})",ival, sval); } } public interface ITest : IXmlRpcProxy { [XmlRpcMethodAttribute("Test.getInt")] int GetInt(); [XmlRpcMethodAttribute("Test.getString")] string GetString(); [XmlRpcMethodAttribute("Test.getData")] Data GetData(); [XmlRpcMethodAttribute("Test.getListOfInts")] int[] GetListOfInts(); [XmlRpcMethodAttribute("Test.getListOfStrings")] string[] GetListOfStrings(); [XmlRpcMethodAttribute("Test.getListOfData")] Data[] GetListOfData(); [XmlRpcMethodAttribute("Test.add")] int Add(int a, int b); [XmlRpcMethodAttribute("Test.concat")] string Concat(string a, string b); [XmlRpcMethodAttribute("Test.modify")] Data Modify(Data o); } public class Program { public static void Dump(T[] a) { Console.WriteLine("[" + String.Join(",", a.Select(e => e.ToString()).ToArray()) + "]"); } public static void Test(string urlstr) { Console.WriteLine(urlstr); ITest client = XmlRpcProxyGen.Create(); client.Url = urlstr; { int v = client.GetInt(); Console.WriteLine(v); } { string s = client.GetString(); Console.WriteLine(s); } { Data d = client.GetData(); Console.WriteLine(d); } { int[] lst = client.GetListOfInts(); Console.WriteLine("[" + String.Join(",", lst) + "]"); } { string[] lst = client.GetListOfStrings(); Console.WriteLine("[" + String.Join(",", lst) + "]"); } { Data[] lst = client.GetListOfData(); Console.WriteLine("[" + String.Join(",", lst.Select(e => e.ToString()).ToArray()) + "]"); } { int v1 = 123; int v2 = 456; int v3 = client.Add(v1, v2); Console.WriteLine(v3); } { string s1 = "ABC"; string s2 = "DEF"; string s3 = client.Concat(s1, s2); Console.WriteLine(s3); } { Data d = new Data { ival = 123, sval = "ABC" }; Data d2 = client.Modify(d); Console.WriteLine(d2); } } public static void Main(string[] args) { Test("http://localhost:8001/"); Test("http://localhost:8002/"); Test("http://localhost:8003/"); } } }