I am used to creating a .Net Framework console application and exposing a Add(int x, int y) function via a WCF service from scratch with Class Library (.Net Fra
WCF is not supported in .NET Core since it's a Windows specific technology and .NET Core is supposed to be cross-platform.
If you are implementing inter-process communication consider trying the IpcServiceFramework project.
It allows creating services in WCF style like this:
Create service contract
public interface IComputingService
{
float AddFloat(float x, float y);
}
Implement the service
class ComputingService : IComputingService
{
public float AddFloat(float x, float y)
{
return x + y;
}
}
Host the service in Console application
class Program
{
static void Main(string[] args)
{
// configure DI
IServiceCollection services = ConfigureServices(new ServiceCollection());
// build and run service host
new IpcServiceHostBuilder(services.BuildServiceProvider())
.AddNamedPipeEndpoint(name: "endpoint1", pipeName: "pipeName")
.AddTcpEndpoint(name: "endpoint2", ipEndpoint: IPAddress.Loopback, port: 45684)
.Build()
.Run();
}
private static IServiceCollection ConfigureServices(IServiceCollection services)
{
return services
.AddIpc()
.AddNamedPipe(options =>
{
options.ThreadCount = 2;
})
.AddService();
}
}
Invoke the service from client process
IpcServiceClient client = new IpcServiceClientBuilder()
.UseNamedPipe("pipeName") // or .UseTcp(IPAddress.Loopback, 45684) to invoke using TCP
.Build();
float result = await client.InvokeAsync(x => x.AddFloat(1.23f, 4.56f));