Running WCF SOAP service in docker windows container

Somak Das
5 min readNov 18, 2018

Microservices are one of the leading architectures right now. Many of the ideas and capabilities behind microservices are already possible with the WCF frameworks for client and server communication. There is one tenet about microservices that you can not do with WCF: run inside of a container. In this post I am going to share my experience while trying to run WCF service inside windows docker container. Below is the architecture that we are trying to achieve in this article.

Architecture diagram

If you are new to windows containers and Docker you can go through my previous blog, where I have given a quick introduction to containers and shown quick steps to containerize asp.net Mvc application and run it in Docker.

Before moving forward lets be very clear that WCF services are not as frequently used now a days, for client server architecture REST full web api are preferred option. But there were legacy applications which were written in WCF, so this blog is for those who are/will be working on migration activities like migrating on-prem application to cloud specific application or to containers.

For this example we are going to consider that we already have a WCF web service which we would containerize.

In order to run the WCF service with in container, there are two main methods:

  1. WCF self hosting with in windows container : There is already a great blog on this process. Please refer to the below article for a detailed explanation of this method.

2. WCF IIS hosting with in container:

This basically means we are going to host our WCF service in IIS inside our windows container. Lets look in the steps on how we can easily achieve this.

Step 1: Choose your base image for the container

While writing the docker file we first need to choose the base docker image. The easiest and recommended image that we can use is the official microsoft/wcf image for WCF services. Please find the link to the docker image below:

https://hub.docker.com/r/microsoft/wcf

Else we can choose microsoft/aspnetmvc image, which comes with IIS pre installed. Of course you can go ahead and start from scratch with a very basic windows container and generate your docker image.

In this post we are going to use the microsoft/aspnetmvc image as base image. Doing so we will be able to understand the exact configuration, that are required to run WCF service which are available in the microsoft/wcf image out of the box.

Step 2: Enable windows features required for WCF service to run in IIS

Now this step is for those who is building the docker image from scratch or for those who are using the microsoft/aspnetmvc image. Basically the official docker image for WCF service already has these required features enabled. But in order to understand in depth lets go ahead and see what all features are basically required.

# Install Windows components required for WCF service hosted on IISRUN

Add-WindowsFeature NET-WCF-TCP-Activation45

Add-WindowsFeature NET-WCF-HTTP-Activation45

Add-WindowsFeature Web-WebSockets

These are the powershell commands that are required to run inside the container to enable features that are necessary for WCF service to run. You might need to run only the specific command as per requirement of which protocol your WCF service supports. Since the one that I worked on required only HTTP protocol I had to add only Add-WindowsFeature NET-WCF-HTTP-Activation45.

Step 3: Create the docker file

Lets 1st look at a sample docker file using microsoft/wcf as base image that you might use to run your WCF service with in windows container.

# install WCF basic docker image 
FROM microsoft/wcf:4.6.2
# Next, this Dockerfile creates a directory for your application
WORKDIR WcfServiceTest
# configure the new site in IIS.
RUN powershell -NoProfile -Command \
Import-module IISAdministration; \
New-IISSite -Name "WcfServiceTest" -PhysicalPath C:\WcfServiceTest -BindingInformation "*:83:"
# This instruction tells the container to listen on port 83.
EXPOSE 83
# The final instruction copies the site you published earlier into the container.COPY WcfServiceTest/ .

The above docker file is pretty basic and straight forward. It is using microsoft/wcf as base image which means it is already preconfigured with IIS and all the necessary features enabled to run WCF service.

Rest are docker commands to create work directory inside container, create a new IIS site and expose the container port where its listining to and finally copy the local published WCF service inside the container.

Now lets look at the docker file using microsoft/aspnetmvc as the base image.

The final step would be to run the docker file and test the application locally. I am not going to create a new demo application since there are already sample application that run WCF service in windows container. Please look into the samples already provided in github. There are samples for each type of deployment (IIS, self hosting etc.)

Step 4: Update DNS entry for service(optional)

Finally I would highlight few points here, which might be necessary when you would actually use this strategy to run WCF service inside containers. Lets begin assume that you will have a DNS associated with your service which might be true for most of the cases if the service is public is available. In that case for the service proxy to get downloaded properly, you will need to set the HostHeader property in IIS against your website where you are hosting your service. The powershell command to do that is below:

Set-WebBinding -Name ‘Your  Application’ -BindingInformation “*:80:” -PropertyName HostHeader -Value “Your DNS entry”

Conclusion:

Hope this article will help you to get started with deploying WCF service inside windows container. Rest all properties of WCF service will be available while running inside windows containers. You can use powershell inside docker image to play around with different IIS settings, you only need to import IISAdministration module in powershell as shown in the sample docker file above.

Note: I have used only HTTP binding for my project haven’t tried other bindings. 

Let me know in comments in case I have missed anything in this article.

Till then keep coding :)

--

--

Somak Das

Cloud architect | Polyglot Programmer | Digital Entrepreneur | Affiliate marketer | www.instagram.com/digital_somak