Extend your .NET WCF codebase’s life expectancy with CoreWCF

Guillaume Delahaye
Just-Tech-IT
Published in
2 min readJan 26, 2022

Windows Communication Framework

WCF launched during the .NET Framework 3.0 epoch, 15 years ago. It brought a clean abstraction and API to implement communication layers in .NET by separating contracts, endpoints and bindings. It also brought the support of a large choice of protocols and standards to implement WS-* web services but also TCP-based communication layers, all of which are the reason was largely adopted by companies.

The container orchestration hosting model

Throughout the last decade the move to the cloud has changed how we deploy applications but also changed what the smallest expected featureset provided by a platform is. The rise of the container orchestrated model and the need for cloud provider reversibility led us to a point where a technology that is not able to run in a linux based container will probably decline.

.NET Core

The launch of the OSS .NET Core framework in the second part of the 2010s addressed this dead way watching.NET Framework by supporting non-Windows Server OS deployment. ASP.NET Core was released but WCF was left out until Microsoft started the OSS project CoreWCF.

CoreWCF

CoreWCF is a port of WCF on .NET Core and aims to support server side WCF code thus offering a smooth migration path towards linux based containers. The project is supported by the .NET Foundation and the main contributors are Microsoft and AWS.

Now let’s try it

Open a command prompt cd whereever you want, create a new directory, cd inside the fresh directory and typedotnet new webthen code . .

Open your csprojfile and install System.ServiceModel.Primitives and CoreWCF.HttpNuget packages.

Open Startup.cs , define a contract and its service implementation.

[System.ServiceModel.ServiceContract]
public interface IIdentityService
{
[System.ServiceModel.OperationContract]
string Echo(string input);
}
public class IdentityService : IIdentityService
{
public string Echo(string input) => input;
}

Go to the ConfigureServicesmethod and register CoreWCF services

public void ConfigureServices(IServiceCollection services)
{
services.AddServiceModelServices();
}

Go to your application pipeline builder and register your service endpoint

public void Configure(IApplicationBuilder app)
{
app.UseServiceModel(builder =>
{
builder.AddService<IdentityService>();
builder.AddServiceEndpoint<IdentityService, IIdentityService>(new BasicHttpBinding(), "/IdentityService");
});
}

Add a Dockerfile to your project (right click, Add Docker support when using Visual Studio), press F5.

You are running WCF on a linux container.

Links:

CoreWCF/CoreWCF: Main repository for the Core WCF project (github.com)

CoreWCF | The home of CoreWCF blog posts and future documentation

Supporting development of Core WCF | AWS Open Source Blog (amazon.com)

CoreWCF Nuget trends

--

--