Skip to content

Instantly share code, notes, and snippets.

@marcosbozzani
Created April 13, 2020 20:20
Show Gist options
  • Save marcosbozzani/83515648ef4ff678bfae7843a8de2f69 to your computer and use it in GitHub Desktop.
Save marcosbozzani/83515648ef4ff678bfae7843a8de2f69 to your computer and use it in GitHub Desktop.
xmlrpcnet with default values
using CookComputing.XmlRpc;
using System;
namespace XmlRpcClient
{
class Program
{
static void Main(string[] args)
{
var service = XmlRpcProxyGen.Create<ICalcService>();
Console.WriteLine($"1: {service.Add(1)}");
Console.WriteLine($"1 + 2: {service.Add(1, 2)}");
Console.WriteLine($"1 + 2 + 3: {service.Add(1, 2, 3)}");
Console.WriteLine("XmlRpcClient. Press any key to exit");
Console.ReadKey(true);
}
}
[XmlRpcUrl("http://127.0.0.1:5678/calc")]
public interface ICalcService : IXmlRpcProxy
{
[XmlRpcMethod("add")]
int Add(int a, int b = 0, int c = 0);
}
}
using CookComputing.XmlRpc;
using System;
using System.Runtime.Remoting;
namespace XmlRpcServer
{
class Program
{
static void Main(string[] args)
{
RemotingConfiguration.Configure("XmlRpcServer.exe.config", false);
RemotingConfiguration.RegisterWellKnownServiceType
(
typeof(CalcService), "calc", WellKnownObjectMode.Singleton
);
Console.WriteLine("XmlRpcServer. Press any key to exit");
Console.ReadKey(true);
}
}
public class CalcService : MarshalByRefObject
{
[XmlRpcMethod("add")]
public int Add(int a, int b = 0, int c = 0)
{
return a + b + c;
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<system.runtime.remoting>
<application>
<channels>
<channel ref="http" bindTo="127.0.0.1" port="5678">
<serverProviders>
<formatter type="CookComputing.XmlRpc.XmlRpcServerFormatterSinkProvider, CookComputing.XmlRpcServerV2" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment