Skip to content

adospace/IpcServiceFramework

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

IpcServiceFramework

A .NET Core lightweight inter-process communication framework allowing invoking a service via named pipeline and/or TCP (in a similar way as WCF, which is currently unavailable for .NET Core).

Support using primitive or complexe types in service contract.

Support multi-threading on server side with configurable number of threads (named pipeline endpoint only).

ASP.NET Core Dependency Injection framework friendly.

Usage

  1. Create an interface as service contract and package it in an assembly to be shared between server and client.
  2. Implement the service and host it in an console or web applciation
  3. Invoke the service with framework provided proxy client

Downloads

IpcServiceFramework is available via NuGet:

Quick Start:

Step 1: Create service contract

    public interface IComputingService
    {
        float AddFloat(float x, float y);
    }

Note: This interface is ideally to be placed in a library assembly to be shared between server and client.

Step 2: Implement the server

  1. Create a console application with the following 2 NuGet packages installed:
> Install-Package Microsoft.Extensions.DependencyInjection
> Install-Package JKang.IpcServiceFramework.Server
  1. Add an class that implements the service contract
    class ComputingService : IComputingService
    {
        public float AddFloat(float x, float y)
        {
            return x + y;
        }
    }
  1. Configure and run the server
    class Program
    {
        static void Main(string[] args)
        {
            // configure DI
            IServiceCollection services = ConfigureServices(new ServiceCollection());

            // build and run service host
            new IpcServiceHostBuilder(services.BuildServiceProvider())
                .AddNamedPipeEndpoint<IComputingService>(name: "endpoint1", pipeName: "pipeName")
                .AddTcpEndpoint<IComputingService>(name: "endpoint2", ipEndpoint: IPAddress.Loopback, port: 45684)
                .Build()
                .Run();
        }

        private static IServiceCollection ConfigureServices(IServiceCollection services)
        {
            return services
                .AddIpc(builder =>
                {
                    builder
                        .AddNamedPipe(options =>
                        {
                            options.ThreadCount = 2;
                        })
                        .AddService<IComputingService, ComputingService>();
                });
        }
    }

Note: It's possible to host IPC service in web application, please check out the sample project IpcServiceSample.WebServer

Step 3: Invoke the service from client process

  1. Install the following package in client application:
$ dotnet add package JKang.IpcServiceFramework.Client
  1. Add reference to the assembly created in step 1 which contains IComputingService interface.

  2. Invoke the server

    IpcServiceClient<IComputingService> client = new IpcServiceClientBuilder<IComputingService>()
        .UseNamedPipe("pipeName") // or .UseTcp(IPAddress.Loopback, 45684) to invoke using TCP
        .Build();

    float result = await client.InvokeAsync(x => x.AddFloat(1.23f, 4.56f));

Welcome to raise any issue or even provide any suggestion/PR to participate this project!

About

.NET Core Inter-process communication framework

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%