简体   繁体   English

如何在运行中运行WCF服务库

[英]How can I run my WCF Service Library “in process”

I have a WCF CRUD REST API up and running in a Windows Service. 我已经在Windows服务中启动并运行了WCF CRUD REST API。 All is well. 一切都很好。

I'd like to offer the user the ability to run that inprocess as well; 我也想为用户提供运行该进程的能力。 so, instead of running a service (which would require admin) I'd like to have a static library version as well. 因此,我希望运行一个静态库版本,而不是运行服务(这需要管理员)。

With .NET (C#) how would I go about this? 使用.NET(C#),我将如何处理? Right now I have: 现在我有:

ServiceLib (interesting code)
ConsoleHost
GUI

I'd like the GUI to selectively be able to run the ServiceLib code as a full-fledged Windows Service -OR- just as in-process code. 我希望GUI能够选择性地将ServiceLib代码作为完整的Windows Service -OR-作为进程内代码运行。 The service way already works, which I assume is harder. 服务方式已经有效,我认为这很难。

If you run it now in a Windows service it's already self-hosting, I assume? 如果您现在在Windows服务中运行它,它已经是自托管的了,我认为是吗? If GUI app will be the only one using the service in the "in process" mode you can split your "WCF CRUD REST API" ServiceLib into two - one implementing CRUD part and second implementing WCF REST API on top of it. 如果GUI应用程序将是唯一一个在“处理中”模式下使用该服务的应用程序,则可以将“ WCF CRUD REST API” ServiceLib分为两个部分-一个实现CRUD部分,第二个实现WCF REST API。 In GUI you'll need only the CRUD part, so no need to bother with self-hosting of REST API in the same (and only) application that's going to call it. 在GUI中,您只需要CRUD部分,因此无需费心在将要调用它的同一(唯一)应用程序中使用REST API进行自我托管。

Running a GUI app as a Windows service is usually a pretty bad idea anyway from the sysadmin's point of view. 从sysadmin的角度来看,将GUI应用程序作为Windows服务运行通常不是一个好主意。 I often run console apps that can be either WCF hosting Windows services or just WCF hosts, but their only GUI is ablility to react to Ctrl-C. 我经常运行控制台应用程序,这些应用程序既可以是WCF托管Windows服务,也可以只是WCF主机,但是它们唯一的GUI能够响应Ctrl-C。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM