Runtime information with Microsoft.Hosting.Extensions.WindowsService - c#

I run a web API as windows service with Microsoft.Extensions.Hosting.WindowsService.
This allows me to run it as service or as console app (if I just click the exe).
Actually pretty sweet.
But is there a way to detect how it is running (console app or windows service) at runtime?
Would be interersting to have this in the logs ...

Related

Always running web service

I've just created a simple asp.NET web service application with a WebMethod that passes the current server time and a Windows form application to run alongside this as a client.
As it stands, for the client app to be able to interact with the server app, the web service application needs to be running (runs in a web browser). If the browser is then closed, the client app cannot talk to the web service app.
Ideally, I would need this web service to always be running in the background on my server at all times (not just when a web browser is opened) and start when the server is booted up.
What would be the best way to achieve this? I have minnimal experience with asp.NET so is there a way to configure the web service to be a background service? Do I need to create a seperate Windows service application that uses asp.NET web services?
Any help appreciated, thanks.
Yes, by default, Visual Studio stops debugging your web application when you close the browser used for debugging... But you shouldn't run your application from Visual Studio. You deploy web applications to IIS. Then they'll start when the machine starts, and they don't need a browser to keep running.

Can I host my console application in IIS?

I've read in some articles that we can create a console application in .NET & we can host that in IIS which makes our console application as web application. Is it a rumour or can we actually do that?
Also, please provide a working example or procedural steps for that, if we could do that?
Thanks
Console application cannot be run as web application in IIS by itself unless you have a web application calling your console application to trigger on it. of course your console application path must be accessible.
Configured framework, run time at ease.

UWP App design on Windows 10 with Windows Service

We are building an assistant UWP app for Windows 10 & Windows Mobile Devices. On Windows 10 we want to offer some sort of security enforcement to the user, e.g. making sure his antivirus is up to date and so on. This should be done through Powershell with Admin privileges.
Question: What would be the best approach here from architecture & user experience point of view?
Idea 1:
Architecture: UWP app communicates with a service (which is written as .NET Core web.api and offers simple REST Interface) and consumes this service through http client.
The service run's as local system. We want to host it in Kestrel webservice as this is supported when targeting .net 4.6. Prototype worked so far but everything runs in debug mode & not sure if there will be some issues with the isolation of UWP apps.
From my point of view, the UWP app is consuming the service through normal http requests which should not be isolated or intercepted in any way, right? There is no difference on consuming a local hosted webapi instead compared to a cloud api from UWP isolation perspective, right?
Idea 2:
User experience: User downloads the app from public store. App checks if it is running on Windows 10, if so, it checks if the helper windows service is already installed (through a API call on the webservice). If not, it offers the user the ability to download the service from a web page and install it (evaluated prompt).
What would be the best way to do it? Just giving a download link to the user? Or can I start a process from a UWP app that prompts to install an MSI? It should be as simple as possible.

Start up a web-service in a windows-based application

I have a quite old web-service (asmx) that run well on IIS. Now there is a need of start this up in a windows-based application e.g. a console application (or perhaps in a windows service)
Is there any way of hosting the current ASMX project in a console application without modifying this? Unfortunatelly we cannot convert this in a WCF.
I appreciate any help on this.

Running Windows Service in Foreground

I have a bat file which is installed as a service. I can run the service on a remote box. This service needs to launch another application. The launched application needs to be visible(run in foreground). Currently the launched application is running in background as the windows service is running in background. How can i make the windows service or both the windows service and the application that it launches run in foreground? I intend to manage the service with the ServiceController class in C#.
I think you should probably read
http://asprosys.blogspot.com.au/2009/03/allow-service-to-interact-with-desktop.html
Making a service to just launch another app is a real security issue, what if your other app gets replaced with something else do you have all the checks in your Service to ensure your app is the app you think it is.
A proper approach is to launch the second application in the user's session, while your Windows service app always runs in session 0.
The approach has been part of my discussion with #RaheelKhan under this thread,
How reliable is adding an application manifest to ensure elevated privileges across windows xp, vista and 7?
It requires proper understanding of Windows sessions, session isolation, and platform invoke.

Categories