Header add

In this article we will learn about What replaces WCF in .Net Core?. I used to creating a .Net Framework console application via WCF service from scratch with Class Library (.Net Framework). I then use the console application to proxy call this function within the server. However if I use Console App (.Net Core) and a Class Library (.Net Core) the System.ServiceModel is not available.

Let's understand here what alternative of WCF in .Net Core.

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 ICalculator
{
int Addcalc(int x, int y);
}
view raw ICalculator.cs hosted with ❤ by GitHub


Implement the service


class Calculator : ICalculator
{
public int AddFloat(int x, int y)
{
return x + y;
}
}
view raw Calculator.cs hosted with ❤ by GitHub

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<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()
.AddNamedPipe(options =>
{
options.ThreadCount = 2;
})
.AddService<ICalculator, Calculator>();
}
}
view raw Program.cs hosted with ❤ by GitHub


Invoke the service from client process

IpcServiceClient<ICalculator> client = new IpcServiceClientBuilder<ICalculator>()
.UseNamedPipe("pipeName") // or .UseTcp(IPAddress.Loopback, 45684) to invoke using TCP
.Build();
int result = await client.InvokeAsync(x => x.Addcalc(12, 15));
view raw Program.cs hosted with ❤ by GitHub


Summary

So far we learnt What replaces WCF in .Net Core. Please give your comments if have any suggestion.
Previous Post Next Post