如何判断WCF服务是否托管在Console应用程序中?

时间:2015-03-08 07:34:33

标签: .net wcf self-hosting servicehost wcf-hosting

我正在开发一个WCF服务,并且经常在Windows服务中托管和在控制台应用程序中托管之间切换。服务和控制台应用程序共享一个配置文件,那么我在WPF客户端中如何判断服务是否在控制台应用程序中托管?

1 个答案:

答案 0 :(得分:2)

bool windowsServiceHosted = !Environment.UserInteractive;

更多hacky(上面不应该有用)

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;

如果您需要从客户端了解,那么您需要从使用上述服务器端之一的服务器公开bool WindowServicesHosted属性。

相关问题