12

Currently Windows 10 Core for IoT is in Preview, and there is available to use Visual Studio 2015 RC with new Windows Universal project and develop some apps.

However, I am interested in making my own ASP.NET WebAPI (REST / JSON) on Raspberry Pi 2 as a host. Is it possible ? Also is it possible for RPi2 to be a small web server with few .html files at all ?

Hrvoje Kusulja
  • 385
  • 1
  • 4
  • 9

4 Answers4

10

If your looking for a simple REST service for a windows universal app, take a look at this github project:

https://github.com/tomkuijsten/restup

There is also a nuget package for it:

https://www.nuget.org/packages/Restup/

Disclaimer: I'm the owner and creator of restup

Tom Kuijsten
  • 201
  • 2
  • 4
  • This is a great looking project Tom. I had started playing with a similar idea, creating classes to handle different kinds of http requests, but you and your contributors have really built something cool. Can't wait to try it out. – Ben Brandt May 27 '16 at 14:00
  • Is this your project? Please provide disclaimer on your answer about that. PS Cant you host MVC on IoT? – Piotr Kula Jun 16 '16 at 06:55
  • Indeed my project, disclaimer added. And no, you can't host MVC on IoT. – Tom Kuijsten Jun 17 '16 at 09:08
  • Indeed. MVC requires either IIS or .NET Core, neither of which are supported (yet) on Win IoT. Eventually .NET Core will be supported though. – Jim Yarbro Jul 31 '16 at 13:36
  • @TomKuijsten Thank you for your contribution. If I may ask, would you still suggest I use your implementation? Is it "up to date", cause I see the current thread is from 3 years ago. If not, do you have an alternative in mind? – Thodoris Koskinopoulos Sep 30 '18 at 16:11
  • @ThodorisKoskinopoulos as you already figured out, I'm not actively developing on it :) One of the last things I did in this regard was using asp.net core on the pi. If that's still not working, I would go use asp.net core with a linux distro on the pi. – Tom Kuijsten Oct 03 '18 at 20:43
4

Also check out Embedded HTTP and WebSocket Server for UWP/.NET 4.5 https://www.nuget.org/packages/IotWeb/ (or on github)

  • does this nuget package have any example or how to documentation associated with it? Thanks! – Rob S. Aug 13 '16 at 04:34
  • 1
    @RobS. documentation is light, but they have examples here https://github.com/sensaura-public/iotweb/blob/f2b58aff19a81cc605d261bc4f07e54f7cbc4b98/WebHost%20Desktop/Program.cs and here https://github.com/sensaura-public/iotweb/blob/f2b58aff19a81cc605d261bc4f07e54f7cbc4b98/WebHost%20UWP/App.xaml.cs and I'm combining it with an Angular2 app for something a little more more substantial here: https://github.com/AutomatedArchitecture/sirenofshame-uwp/blob/develop/SirenOfShame.Uwp.Background/StartupTask.cs#L34 – Lee Richardson Aug 15 '16 at 16:50
3

It's possible to implement a web server with Windows 10 Core for IoT on the Raspberry Pi 2. If you access your device on http://devicename/, you will actually see a website that is already provided by the system.

To implement your own web server on Windows IoT, there are a bunch of possibilities. For Python or Node.js, there are already samples available on the official GitHub project:
https://github.com/ms-iot/samples

As you mentioned ASP.NET: I didn't stumble across any sample yet, but you should be able to do that, either with a classic self-hosted ASP.NET 4 application or you could give it a try with ASP.NET 5 (aka "ASP.NET vNext").

In both cases, you should create a Windows Universal App first, which will host the web server. Now, you can follow the same approach as described in several tutorials out there that demonstrate how to implement a self-hosted ASP.NET server, e.g. using a console application. Instead of a console application you are using the Windows Universal App here, but that basically doesn't make a difference.

ASP.NET 4 sample :
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api

ASP.NET 5 sample:
http://www.c-sharpcorner.com/UploadFile/7ca517/Asp-Net-5-conaole-application-with-visual-studio-2015/

Hope that helps!

Daniel Lemke
  • 171
  • 3
  • Thank you for info, yes, I want mentioned Windows Universal App with ASP.NET 4 or 5 self-hosted, however not sure about this when using Universal App instead of simple console app. Use of OWIN web server in .net is not allowed for Windows Universal App projects, or only for IoT.. – Hrvoje Kusulja Jun 11 '15 at 12:24
  • Hi, I am after the same thing but am not bothered by using OWIN. I would just like to server html pages via my raspberry pi2 with windows 10 installed. there is no default page to my device? –  Oct 25 '15 at 18:29
0

Note that the "App2App WebServer" sample application uses sockets to listen for a connection. You can easily extend the code to read the content and treat process the content as JSON if you want to do your own simple Restful server. It won't have all the ASP.NET mechanism but then you want simple.