Git Product home page Git Product logo

remoting's Introduction

windows build & test Nuget

Remoting

This repo provides a simple RMI and IPC library for .NET Framework 4.8 and .NET 6.0+ applications. It's designed to help ease the migration from legacy WCF and .NET Remoting when porting code from .NET Framework to modern .NET. However, this library doesn't try to do all the things like WCF and .NET Remoting.

Menees.Remoting:

  • Prefers simplicity over performance.
  • Is designed for non-chatty communication.
  • Can't pass or return a .NET reference directly.
  • Requires values to be serialized going to and from the server.
  • Uses named pipes and a serializer of your choice (default is System.Text.Json).
  • Doesn't use or care about MarshalByRefObject, OperationContract, ServiceContract, etc.

RMI

Menees.Remoting provides RmiClient to invoke .NET interface methods in a remote RmiServer. The server process exposes a .NET interface for a given instance object. Then one or more client processes invoke .NET interface methods on the server's instance object. .NET's DispatchProxy.Create is used to generate the interface proxy, so clients can invoke the interface methods as normal C# calls.

[TestMethod]
public void HasherExample()
{
    const string ServerPath = "Menees.Remoting.RmiClientTests.HasherExample";

    using RmiServer<IHasher> server = new(new Hasher(), ServerPath);
    server.Start();

    using RmiClient<IHasher> client = new(ServerPath);
    IHasher proxy = client.CreateProxy();

    proxy.Hash(new byte[] { 1, 2, 3, 4 }).Length.ShouldBe(20);
    proxy.Hash("Testing").ShouldBe("0820b32b206b7352858e8903a838ed14319acdfd");
}

internal interface IHasher
{
    byte[] Hash(byte[] data);
    string Hash(string text);
}

internal class Hasher : IHasher
{
    public byte[] Hash(byte[] data)
    {
        using HashAlgorithm hasher = SHA1.Create();
        return hasher.ComputeHash(data);
    }

    public string Hash(string text)
    {
        byte[] hash = this.Hash(Encoding.UTF8.GetBytes(text));
        return string.Concat(hash.Select(b => $"{b:x2}"));
    }
}

For more usage examples see:

Due to the synchronous API of the underlying DispatchProxy.Invoke method, all the client invocations are sent synchronously to the server. The RmiClient can't do asynchronous calls to the RmiServer due to risks with sync over async. For more on DispatchProxy's lack of InvokeAsync support see #19349 and the comments for Migrating RealProxy Usage to DispatchProxy.

IPC

Menees.Remoting provides MessageClient to send a TIn-typed request message to a MessageServer and receive a TOut-typed response message. Message IPC only supports asynchronous calls, and the server requires a lambda that takes a TIn and returns a Task<TOut>.

[TestMethod]
public async Task Base64ExampleAsync()
{
    const string ServerPath = "Menees.Remoting.MessageNodeTests.Base64ExampleAsync";

    using MessageServer<byte[], string> server = new(data => Task.FromResult(Convert.ToBase64String(data)), ServerPath);
    server.Start();

    using MessageClient<byte[], string> client = new(ServerPath);
    string response = await client.SendAsync(new byte[] { 1, 2, 3, 4 }).ConfigureAwait(false);
    response.ShouldBe("AQIDBA==");
}

For more usage examples see:

No .NET Standard 2.0 Support

This library doesn't target .NET Standard 2.0 because that standard doesn't support:

remoting's People

Contributors

menees avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.