Real-Time Talk: Windows 10 IoT Core Background Tasks and ASP.NET Core Web Apps

DZone 's Guide to

Real-Time Talk: Windows 10 IoT Core Background Tasks and ASP.NET Core Web Apps

Learn how to display useful information from your Windows 10 IoT Core application in an ASP.NET Core web app, essential for integrating IoT data into a solution.

· IoT Zone ·
Free Resource

My previous blog post introduced how to make an ASP.NET Core 2 web application run on Windows 10 IoT Core. It was a default web application created on Visual Studio and published as an executable. But this is not enough for IoT scenarios. When we build a web application that runs on an IoT board, we need this application to do something — displaying sensor data or controlling some hardware, etc. This blog post shows how to make a Windows 10 IoT background task talk with a web application using WebSockets.


As my path to this solution has been troublesome, I am listing here the main problems I faced so my dear readers have a better idea of dead-end streets along the way:

  • I was not able to make the ASP.NET Core web application run under a Windows 10 IoT background service.
  • I found no information about when or if it will be supported in the near future.
  • ASP.NET MVC and ASP.NET Core have different SignalR implementations.
  • I was not able to make a SignalR client for .NET Core work with SignalR hosted on a web application.

I was able to make things work by directly using a WebSocket. It’s not as nice a solution as I had in my mind, but it works until things get better.

Making the Background Task and Web Application Talk

I worked out simple and not-very-well polished solution to make a Windows 10 IoT Core background task communicate with an ASP.NET Core web application hosted on a Raspberry Pi. I implemented two types of communication on the same WebSocket endpoint. The following image illustrates what is supported.

Windows 10 IoT Core background task and ASP.NET Core web application

To make my sample more informative, I also implemented some primitive functionalities to demonstrate how data moves.

  1. The Windows 10 IoT Core background task reports random numbers to the web application every 10 seconds.
  2. The web application has a simple console to send commands to the Windows 10 IoT Core background task. Supported commands are:
    1. opsys: returns operating system information from the background task
    2. machine name: returns the machine name where the background task runs

Here is a fragment of the web application's front page when the background service runs.

WebSocket sample output with command

Source Code and References

I made my work available at my GitHub repository. There are background service and web applications. The web application must be built and then deployed to the Raspberry Pi. Here are some links to help get started:

Please feel free to give me feedback about better solutions available.

web application ,windows 10 iot core ,asp.net core 2.0 ,iot ,raspberry pi ,tutorial

Published at DZone with permission of Gunnar Peipman , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}