Blog

Filter posts by Category Or Tag of the Blog section!

WCF replacement in .Net Core

Saturday, 26 May 2018

As you know, WCF is Windows Communication Service and doesn't match the targets of .Net Core which is cross-platform. It was a just a question to know how can I handle the WCF services in .Net core. Reference the following Nuget Pacakges to your project:

  1. JKang.IpcServiceFramework.Client
  2. JKang.IpcServiceFramework.Server

 

And assume that your services are like below:

  

public interface IMyService

        {

        }

 

        public class MyService : IMyService

        {

        }

 

In order to register and use them in asp.net core add some piece of code to the ConfigureServices of Startup class:

 

 public void ConfigureServices(IServiceCollection services)

        {

            services.Configure<CookiePolicyOptions>(options =>

            {

                // This lambda determines whether user consent for non-essential cookies is needed for a given request.

                options.CheckConsentNeeded = context => true;

                options.MinimumSameSitePolicy = SameSiteMode.None;

            });

 

 

            services.AddIpc(serviceBuilder =>

                 {

                     serviceBuilder.AddNamedPipe(options =>

                         {

                             options.ThreadCount = 2;

                         }).AddService<IMyService, MyService>();

                 });

 

            new IpcServiceHostBuilder(services.BuildServiceProvider())

               .AddNamedPipeEndpoint<IMyService>(name: "endpointA", pipeName: "pipeName")

               .AddTcpEndpoint<IMyService>(name: "endpointB", ipEndpoint: IPAddress.Loopback, port: 564)

               .Build()

               .Run();

 

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

        }

 

comments powered by Disqus