1

I'm working on an application that requires me to host a WCF REST Web App using Windows Service. Now since it is going to be a bit more complicated than just a small API, I would like leverage MVC capabilities as a lot of things would be lot easier if done using the 'Controller' way (if I can say so). I'm don't have deep knowledge of MVC and Windows Service.

So far, I've found only two links here & here, that are somewhat related to what I want, but still not there. Could anyone please point me to a working example or create a small demo? TIA.

Kunal Patel
  • 95
  • 1
  • 12
  • If you are using .NET Core then support is built in using the "Kestrel" web-server. If you are using .NET Framework then you can use OWIN to host it. Please clarify in your question which you are expecting to use (or if you don't mind/don't know). Also, a useful Google search term is "self hosting". – RB. Sep 28 '16 at 14:36
  • Also, it's unclear from your question if you are writing a REST Web API, or an MVC web-site - please clarify which (you can't self-host an MVC web-site using Owin). – RB. Sep 28 '16 at 14:37
  • Is it an option creating a web api? If so, just host it in iis – Morten Toudahl Sep 28 '16 at 15:41
  • @RB. I will have a look at both OWIN and Kestrel. I'm using normal .NET4.5.2 on VS2015. 'Self hosting' (assuming that means windows service) is noted for future, thanks. I've written REST styled web service that is running in windows service. I always thought MVC is also a REST styled architecture, no? However, I wish to have MVC site that can run within Windows Service, but can also be used to receive data via, says, POSTMAN or Fiddler tool. – Kunal Patel Sep 29 '16 at 08:26
  • @MortenToudahl - IIS might not be an option, as I've been told that it **might** have to run within Linux server. But also been told that for initial stage, I can experiment with it. – Kunal Patel Sep 29 '16 at 08:29
  • ASP.NET MVC is not a REST architecture - it's an MVC architecture! MVC is a pattern for how you structure and develop your service - REST details how you call the service. I *strongly* encourage you to read up on, and understand, both MVC and REST. Your confusion might stem from the fact that ASP.NET WebAPI (which, in .NET Framework is distinct from ASP.NET MVC, but in .NET Core is unified with ASP.NET MVC) is a framework to implement REST APIs. – RB. Sep 29 '16 at 08:30
  • @KunalPatel If you need it to run on Linux, you are *really* going to want to use .NET Core. You *can* use .NET Framework with Linux by running it on top of an implementation of the CLR called Mono, but .NET Core is fully supported on Linux by Microsoft. – RB. Sep 29 '16 at 08:32
  • @RB. Thank you, I shall have a read about it. But now that you've briefed me, I think I would need ASP.NET MVC but on .NET Core that can be self hosted – Kunal Patel Sep 29 '16 at 08:34
  • @RB. Any examples of MVC on .NET Core that are self-hosted, that you can point me to? – Kunal Patel Sep 29 '16 at 08:37
  • Luckily for you, the docs for ASP.NET Core are *much* better than the docs for ASP.NET 5 - see https://docs.asp.net/en/latest/tutorials/first-web-api.html for a fully featured example :) – RB. Sep 29 '16 at 08:37
  • @RB. Thank you, I shall have a look at it, after I've installed .NET Core. :-) – Kunal Patel Sep 29 '16 at 08:40
  • @RB. How do I mark your comment as an answer? – Kunal Patel Oct 07 '16 at 14:24
  • @KunalPatel I've posted an answer for you to accept. Hope you got it running :) – RB. Oct 07 '16 at 15:39
  • @RB. I created a WebAPI Project using ASP.NET Core (not impressed at all by the usage of `project.json` file, instead of `.csproj` file!), that also returns `Views`, apart from the standard API so that it can also be used as it is to render pages. Hope this helps someone. – Kunal Patel Oct 10 '16 at 14:16
  • @KunalPatel They are moving back to `proj` files in the next realease! See http://stackoverflow.com/questions/38536978/is-project-json-deprecated. – RB. Oct 10 '16 at 14:20
  • @RB. I sincerely hope that change comes around rather quickly. Feels uneasy while transitioning from _classic_ Visual Studio to this. – Kunal Patel Oct 10 '16 at 14:43
  • @RB. I've posted a new question [here](http://stackoverflow.com/q/39962402/4483601), that you might be able to help me about. – Kunal Patel Oct 10 '16 at 16:12

2 Answers2

1

Based on your comments, it is clear that you are wanting to run REST-based web-services, self-hosted, on both Linux and Windows.

The recommended way to do this is to use the new ASP.NET Core platform, running on .NET Core.

Microsoft provide a good tutorial here: https://docs.asp.net/en/latest/tutorials/first-web-api.html

RB.
  • 36,301
  • 12
  • 91
  • 131
0

Another link just received from a quick google search Here but yes need some more clarity on how you plan to run it or what its for.

We used Nugent package manager years ago for self-hosting a web API

  • Thanks but I already have a WCF REST Web Service running as a windows service. What I'm looking for is MVC site (which is a REST styled API, I think) within windows service. – Kunal Patel Sep 29 '16 at 08:17