Web API as a windows service - asp.net

So I'm creating a new .Net Framework 4.8 Web API in Visual Studio 2019 and I'm wanting to know how to create the API as a windows service? I can't seem to find any examples or online resources to do so. I can run the API locally in VS and it opens Chrome and shows the responses under the local IIS Server it spins up. How do I take this same project and compile it as a windows service while still using HTTPS?

Web API is fully capable of being self hosted on top of OWIN, and does not require IIS to run.
Web API self hosted is basically just a console app. So the techniques for turning a Web API console app into a Windows Service are the same as for any other .NET console app. You can use a service manager such as NSSM, or create a Windows service project directly (by inheriting from the appropriate classes, pretty messy) or use a library like TopShelf.
Note that it's generally not a good idea to directly expose this self hosted app directly to the public. IIS provides a lot of security benefits out of the box designed to protect against malicious requests. If you're planning to publicly expose it, make sure you stick a proxy in front of it that will fulfill those security needs.

Related

cross-compile ASP.NET website to desktop?

Is there a way to cross-compile or port an ASP.NET based webpage to a native Windows GUI?
I am developing a web app, with an ASP.NET webservice doing much of the grunt work, and an ASP.NET webpage as the GUI. I would like to also offer an "offline" version of the app that doesn't require teaching random people how to manage IIS. Some of my target users will not have internet access consistently when they want to use the app; also, I like not having to rely on an active web connection myself because I'm an old fogey and this web 2.0 stuff is just a fad, right?
The core of the app logic is a library that is disassociated from everything else - the service just provides an API (which I want publicly available for others to use), and that I use for my own app. I could go ahead and design a new GUI in WPF or WinForms, import my libraries and there you go, but I'm lazy enough that I'm curious if there's an automated solution. Or even a semi-automated solution.
If I can target not-Windows as well, that would be nice. I already have a console interface that I used in development of the core library that directly accesses them, which I'm still testing but should relatively easy to make work in WINE but if I can offer more support for offline use to non-Windows users I'd feel better.
You could run that web application on .NET Core in a self-hosted way. That way you get the full IIS feature set and there is no need for the user to configure anything.
You can then use a WebBrowser control to show the application as a GUI app, or just open the web site in the users installed browser.
.NET Core runs on non-Windows as well.

Deploy Web-Api, Asp.net project and a Windows service in one msi project

Is it possible to deploy ;
1- a web-api project
2- a website written in Asp.net
3- a WCF service as windows service
in one msi file using/in Windows Web Installer Project (preferably) or in Wix ?
Yes, it is possible using WiX. I maintain an open source project called IsWiX that even makes it somewhat easy. See:
Create and Package a Windows Service using IsWiX
IsWiX Web Site Demo
The concept behind IsWiX is project templates (scaffolding) and graphical designers that give you a project structure and most heavy lifting for your WiX MSI project. The template already contains examples of IIS configuration that merely need to be uncommented out. If you need a Web API and a Web Site you'll have to clone that part of the code and make a few adjustments. For example a static website typically won't be a web application where a web-api will be. Then you'll use the services designer to define the windows service. The fact that the service hosts a WCF endpoint really doesn't matter.
For that matter, one of the really cool things about WCF is it's possible to eliminate your dependencies on IIS. I've seen solutions using this with no dependency on IIS and this really makes creating installers a lot simpler.

Host ASP.NET App In WCF or Generic Web Server

Objective:
We have a Windows Service/generic EXE that also hosts a WCF service (.Net 3.5). I'd like to be able to take a third party ASP.NET component in a DLL, and host it through that WCF Service.
Is this possible to do, in any way?
It seems like if you want to host a ASP.NET app, it must be through IIS, but we don't use IIS.
Is there any way that we could load the ASP.NET app into memory, make the app available through an endpoint, and receive requests back from the app?
Specifically, we'd like to take the "Microsoft.ReportViewer.WebForms.dll", expose the web form in a web page, and accept any requests back from the web form.
http://msdn.microsoft.com/en-us/library/ms251723.aspx
Looking for anything to get me started. Thx.
From owin.org
"OWIN defines a standard interface between .NET web servers and web applications. The goal of the OWIN interface is to decouple server and application, encourage the development of simple modules for .NET web development, and, by being an open standard, stimulate the open source ecosystem of .NET web development tools."
Essentially Owin implementations, like Katana (OWIN implementations for Microsoft servers and frameworks.), help you self host web apps, even in a Windows NT Service.
According to this post, hosting a WebForms app outside IIS/ASP.NET is not possible.
WebForms are tightly coupled to ASP.NET/IIS and cannot run directly on
OWIN/Katana (e.g. outside of ASP.NET/IIS). However, you should be able
to use Katana's middleware (Security, CORS, etc.) in a WebForms
application.
http://katanaproject.codeplex.com/discussions/571291

Why use an Azure Cloud Service Project instead of an ASP.NET project with the Azure SDK?

I'm playing with Azure asp.net development. I use Visual Studio 2010, with Azure SDK and I'm a newbie to Azure cloud.
I created several apps and deployed them to my testing Azure Web Site. Everything works fine - ASP.NET Web Page, ASP.NET MVC3, even simple GridView binding to an Azure SQL database, which I created earlier and that I manage with Microsoft SQL Management Studio, using ADO.NET. It's really simple.
Now, I learned from some tutorials, that I need to use a Windows Azure Cloud Service Project to make sure that my application will work. But it works without this project, too. So what exactly do I need such a project in my solution for?
There are actually three different ways you could have gotten your ASP.NET app over to the cloud, and the confusion comes because you are seeing elements of two of those options.
A Windows Azure Web Site is just a single ASP.NET application running in Microsoft's data centers (versus on premises) so all of the configuration it needs is already part of the project itself (primarily the web.config), some being exposed via the Azure portal. In many ways, this is similar to web hosting providers.
A Windows Azure Cloud Service is a collection of multiple services, which could be web sites/services (Web Roles) or backend code (Worker Roles). The code for your Azure Web Site could also have been deployed exactly as is as a Web Role, but in that case it would be part of a larger application that potentially contains additional Web and Worker Roles. It's the Cloud Service project itself that provides the additional configuration of those web and worker roles (even if you have just a single role in the cloud service). The Cloud Service offering is considered Platform as a Service.
The other option, for completeness, is to create a Virtual Machine image yourself, install your ASP.NET site, and then have Windows Azure host the Virtual Machine. It's at the opposite end of the 'make it simple to deploy' spectrum, but you get a lot of control over what exactly is on the VM that you deploy. This is the Infrastructure as a Service offering from Azure.
I'm going to assume you're developing for Windows Azure Cloud Services (the foundation PaaS solution of Windows Azure). The Cloud Service project defines your application to the Windows Azure Fabric. If you don't already have one, then odds are your are running your application outside of the local Development Emulator. If you are going to deploy your solution to Windows Azure Cloud Services, you will need to create this project for your application so Windows Azure's Fabric (the secret sauce that will manage your application) knows how to manage the application.
And I'm going to assume the opposite to #BrentDaCodeMonkey - that you're developing for Azure Web Sites, and not Cloud Services - in which case you may have confused yourself with the tutorials, as I don't believe a Cloud Services Project is either necessary or advisable.

ASP.NET Web Forms Applications on Azure (or any cloud hosting)

This is a pretty vague question but I'm struggling a bit to get my head around what is involved in cloud hosting.
Say for instance if I had an asp.net web app using:
- Webforms
- linq to sql
- an sql server database
- Calling some external restful webservices
What would need to be done to host it on a cloud service?
Are there specific code changes that would be required and do these need to be considered in the initial design?
Can sql server and linq to sql be used in this type of setup?
What platform if any would be best suited?
in it's most basic form, Azure is just a highly available web-hosting environment - if you have an ASP.Net web application, you can deploy it to cloupapp.net and it should work.
To try it out, get yourself a Vista/7 machine, download the Azure SDK and VS Tools, and create a new Azure application. There are 2 main parts at this point, the Cloud project, and an ASP.Net Web Application. The ASP.Net will have a "web-role" relationship with the Cloud project. This is as it sounds, it is the visual front-end to the Cloud application, that interacts with visitors.
You can, at this point, just leave it there - it's a normal ASP.Net application with very good hosting. Your SQL connection strings should work, though you may want to consider SQL Azure. You can also host WCF services.
As Manoj points out, Azure does have a different programming model which you can take advantage to produce very robust applications. Azure also has the concept of Worker Roles, which are similar to Managed Services, in that they perform processing without a public interface. Instead, your web-roles take the requests, place them on the Queues, and the worker-roles then pick them up, process and send back responses.
It's a very powerful system, which I haven't fully explored, but the good news is that you don't have to be an immediate expert in the whole system, but can create simple ASP.Net sites as web-roles, deploy those then expand from there.
Have a go, it's well worth it
Toby
AppHarbor is a .NET Platform-as-a-Service. We can host your ASP.NET websites more or less un-modified and without the Visual Studio plugins and other crud that Windows Azure requires.
It depends on what type of cloud hosting are you looking for. There is some cloud hosting which will just give you space for application data like Amazon. While Azure gives you complete application framework which supports your application to be hosted in cloud. But programming in cloud is different programming paradigm than in traditional web form. You will have some limited classes from .Net framework available but better resources for scalability.
You cant directly use sql server in azure application. What you can use SqlAzure services.
Just referring a book which i feel would provide you the answer
Cloud Computing Book
EDIT :
Check this microsoft link
Ramp Up
yes, it is supported and live demo of Asp.NET 4.5 Web Forms available on Microsoft azure websites... you can visit this link for detailed information
Create and deploy a secure ASP.NET Web Forms app with Membership, OAuth, and SQL Database to Azure App Service

Resources