I have a WCF service under development, and often switch between hosting in a Windows Service, and hosting in a Console app. The service and console app share one config file, so how else can I tell, in my WPF client, if the service is hosted in the console app?
bool windowsServiceHosted = !Environment.UserInteractive;
More hacky (shouldnt be necessary above should work)
private bool? _ConsolePresent;
public bool ConsolePresent {
get {
if (_ConsolePresent == null) {
_ConsolePresent = true;
try { int window_height = Console.WindowHeight; }
catch { _ConsolePresent = false; }
}
return _ConsolePresent.Value;
}
}
bool windowsServiceHosted = !ConsolePresent;
If you need to know from client then you'll need to expose a bool WindowServicesHosted
propetry from your server that uses one of the above server side.