IDEV.JRPC is JSON-RPC library based on JSON-RPC.NET. It's provide server and client parts.
- dotnet 4.5.1, dotnetstandard 2.0, dotnetcoreapp 2.0
- Nlog >= 3.1.0
- ConsulClient >= 0.7.2
- Ninject >= 3.2.2 (optional: only for JRPC.Registry.Ninject)
- Microsoft.Owin.Host.HttpListener >= 3.0.1 (for owin hosting)
- Microsoft.AspNetCore.Server.Kestrel (for kestrel hosting)
Also Consul agent needed to work properly.
To install JRPC Service, run the following command in the Package Manager Console:
PM> Install-Package JRPC.Service
To install JRPC Client, run the following command in the Package Manager Console:
PM> Install-Package JRPC.Client
To install JRPC Ninject Registry, run the following command in the Package Manager Console:
PM> Install-Package JRPC.Registry.Ninject
To install JRPC Service Owin Hosting (using for dotnet45), run the following command in the Package Manager Console:
PM> Install-Package JRPC.Service.Host.Owin
To install JRPC Service Kestrel Hosting (using for dotnet46 (and higher), netstandard 2.0 and netcore 2.0), run the following command in the Package Manager Console:
PM> Install-Package JRPC.Service.Host.Kestrel
Add appSettings
section in App.config:
<configuration>
...
<appSettings>
<add key="ServicePort" value="12345" />
<add key="ServiceAddress" value="127.0.0.1" />
</appSettings>
...
</configuration>
public interface ISomeService {
string GetString();
}
public class SomeService : JRpcModule, ISomeService {
public string GetString() {
return "Result from service";
}
}
var consulClient = new ConsulClient();
var registry = new DefaultModulesRegistry();
var host = new OwinJrpcServer();
registry.AddJRpcModule(new SomeService());
var svc = new JRpcService(registry, consulClient, host);
svc.Start();
Console.ReadLine();
svc.Stop();
var consulClient = new ConsulClient();
var registry = new DefaultModulesRegistry();
var host = new KestrelJRpcServerHost();
registry.AddJRpcModule(new SomeService());
var svc = new JRpcService(registry, consulClient, host);
svc.Start();
Console.ReadLine();
svc.Stop();
Define Ninject module like this:
public class SomeNinjectModule : NinjectModule {
public override void Load() {
Bind<JRpcModule>().To<SomeService>();
Bind<IModulesRegistry>().To<NinjectModulesRegistry>();
Bind<IJrpcServerHost>().To<OwinJrpcServer>();
Bind<IConsulClient>().To<ConsulClient>();
Bind<JRpcService>().ToSelf();
}
}
var kernel = new StandardKernel();
kernel.Load<SomeNinjectModule>();
var svc = kernel.Get<JRpcService>();
svc.Start();
Console.ReadLine();
svc.Stop();
public class SomeNinjectModule : NinjectModule {
public override void Load() {
Bind<JRpcModule>().To<SomeService>();
Bind<IModulesRegistry>().To<NinjectModulesRegistry>();
Bind<IJrpcServerHost>().To<KestrelJRpcServerHost>();
Bind<IConsulClient>().To<ConsulClient>();
Bind<JRpcService>().ToSelf();
}
}
var kernel = new StandardKernel();
kernel.Load<SomeNinjectModule>();
var svc = kernel.Get<JRpcService>();
svc.Start();
Console.ReadLine();
svc.Stop();
var client = new JRpcClient("http://127.0.0.1:12345");
var proxy = client.GetProxy<ISomeService>("SomeService");
Console.WriteLine(proxy.GetString()); // Output is "Result from service"
IDEV.JRPC is licensed under The MIT License.