Skip to content

Overview

Hagen Siegel edited this page Apr 21, 2021 · 17 revisions

CoreRemoting is a library that helps develop distributed applications that use RPC communication. The server part of the application provides services for multiple clients.

A service is a class that implement an interface which is shared between server and client. Sharing means that the service interface is defined in separate assembly that is deployed on server and also on client. Clients can call methods of the provided services remotely over the network (Remote Procedure Call).

Because the client only knows the shared interface of the service, but not the service implementation, a proxy for the service is needed. All methods that are called on such a proxy, are serialized (see Serialization chapter for details) and sent over the network to the server. On server side the call is deserialized and dispatched to the real service implementation. After successful execution of the service method, the result is serialized and sent back to the calling client.

To bring that RPC thing to work, CoreRemoting needs the following components:

Interfaces of CoreRemoting server components

Remoting Server Structure

What implementations of this component interfaces a CoreRemoting server instance should use, is defined in it's configuration, which is done via a ServerConfig object. Most properties of the ServerConfig class have default values. If, for example, no channel is explicitly specified in the configuration, a websocket channel is used as default.

To create a new server instance which is configured to to host the SayHelloService class as service, using ISayHelloService as public service interface and listen on localhost at port 9090, the following C# code is needed:

    using var server = new RemotingServer(new ServerConfig()
    {
        HostName = "localhost",
        NetworkPort = 9090,
        RegisterServicesAction = container =>
        {
            container.RegisterService<ISayHelloService, SayHelloService>(ServiceLifetime.Singleton);
        }
    });

    server.Start();         

Interfaces of CoreRemoting client components

Remoting Client Structure

On client side, there is also configuration needed, which is done via a ClientConfig object.

To connect to the server, the following code is needed on client side:

    using var client = new RemotingClient(new ClientConfig()
    {
        ServerHostName = "localhost",
        ServerPort = 9090
    });
    
    client.Connect();

After the client instance is connected to the server, a proxy can be created to call methods on a remote service.

    ISayHelloService proxy = client.CreateProxy<ISayHelloService>();

The diagram below shows the RPC call flow of the "Hello World" example application.

Hello World Application as Diagram

Please also read the security documentation page to learn how to secure your CoreRemoting application.

Clone this wiki locally