great place to work

Azure Service Fabric using Microsoft Owin


In recent times, the techies have been talking about Microservices architecture and jargons related to it like “targeted deployment” etc. Initially, there was ambiguity regarding these terms, but now it’s clear on what is meant by “Microservices Architecture”.

Developers who are working with IIS hosted Web APIs are content with the legacy way of using HttpContext. When we design something related to Microservices or while implementing targeted deployment one should not use IIS hosting and instead, you need to adopt OWIN Self-hosting. No more HttpContext or HttpContext.Current! You don’t even require an IIS express instance to deploy or run an API.

OWIN (Open Web Interface for .NET) defines an abstraction between .NET web servers and web applications. It dissociates the web application from the server which makes OWIN ideal for self-hosting a web application in your own process, outside of IIS.


Azure Service Fabric is a distributed systems platform that makes it easy to package, deploy and manage scalable and reliable Microservices and containers. Service Fabric also, addresses the significant challenges in developing and managing cloud-native applications.

Click here to get a better understanding of Azure Service Fabric.

Some of the challenges using traditional IIS strategy while implementing Microservices are:

  • Manually creating new sites when new APIs are introduced.
  • Maintaining multiple instances of these websites, one for each project.
  • Problems in handling failover scenario.
  • Need for multiple deployments for replications of the same package.
  • Dependency on infrastructure.

These challenges are addressed by introducing Microsoft Azure Service Fabric SDK and Visual Studio 2017 with Azure Services enabled.

A step by step approach

You need to have the Visual Studio 2017 Community / Developer edition and open VS in administrator mode to work with Service Fabric Project. You must have the Service Fabric SDK3.0 or above installed in your machine to have the Service Fabric Local Cluster available. Also, Window Powershell Tools should be pre-installed.

1.Open New Project (Ctrl+Shift+N) – Create a new Service Fabric project. You will get a list of project templates as shown in the image.

New Service Fabric 2. The project is named as “HelloWorldStateless”. When you click OK there will be two projects available in the solution explorer. a) Publisher project & B) Stateless service.
You do not need to code in the Publisher projects. Since it is used for configuring. Publish the deployment activities of the Microservices.

3. Now, open the Stateless service project. You will see files Startup.cs. The file looks like as follows:

4. You have to mention the IOwinAppBuilder as shown below:

5. You need to use Package Manager Console to install all the dependencies related to OWIN.

6. There will be a service class under the name, “HelloWorldStatelessService”. Open the file and add the below code.

7. You need to add Controller Classes similar to a Web API project. A class is added to the Stateless project as shown below.

8. The Default Controller is ready with the Upload Async task with action route “api/UploadFile”.

9. You need to build the Service Fabric project and then right click on the Publisher Project.

10. Select the Publish option and you will see a screen similar to this. You should select options that are similar to what you see in the below image.

11. Finally, click on the “Publish” button. This will publish the Stateless Service to the Azure Service Fabric Local Cluster Nodes.

12. Now, you can go to the Local Cluster in which the service has been deployed.

13. For that select the Manage Local Cluster option from Service Fabric Tray icon as shown below.

14. Once you click on the Manage Local Cluster option, browser windows will get opened at the following URL: http://localhost:19080/Explorer/index.html.

15. You are able to see the applications and nodes in which they are published.

You can see the application published to a random port number.

16. You can use postman to make use of Upload API.

The files have been uploaded to the server.

Happy Coding!

Click the above link to download the code from Git Hub.

Saleedher Muraleedharan
Technical Lead at RapidValue


  1. sheyin says:

    Good attempt Saleedher 🙂 I am sure this article will be very help full for the guys who searching solution for file upload with OWIN middle ware. We know that we struggled lot to implement it.But now you made it easy for them.

Please Share Your Thoughts & Comments Below.

How can we help you?