如何从Windows服务中公开restful接口? [英] How to expose restful interface from windows service ?
问题描述
我写了一个暴露restful接口的wcf服务。
现在我使用iis作为wcf服务主机。
I wrote a wcf service that expose restful interface.
Now i using the iis as the wcf service host.
我需要在我的应用程序上进行一些操作,除了暴露restful之外 - 为此需要我必须将我的应用程序作为Windows服务运行。
但是使用iis作为主机不会使我的wcf服务器作为服务运行。
There are some action that i need to make on my application beside the exposing of the restful - and for this need i must run my application as a windows service. But the using the iis as a host will not make my wcf server run as a service.
如何使用暴露wcf restful接口服务的Windows服务?
How to make it possible to using a windows service with expose wcf restful interface service ?
推荐答案
为了能够在2种不同的主机模型中运行应用程序,您必须将主机内容与主代码分开。关键点:你可以使用在其他库项目中创建的控制器。
To be able to run the app in 2 different host models, you have to separate hosting stuff from you main code. The key point of it: you can use controllers created in the other library project.
我之前做过:
- 创建一个库项目并将所有控制器和其他类移动到那里。
- 创建空的WFC服务,添加对上面的lib的引用并使其正常工作。
- 创建一个空控制台应用程序,引用lib,添加自托管内容并使其正常工作。
- 将topshelf软件包添加到控制台应用程序中能够安装它作为Windows服务。
- Create a library project and move all you controllers and other classes there.
- Create empty WFC service, add reference to the lib above and make it working.
- Create an empty console app, reference to the lib, add self hosting stuff and make it working.
- Add topshelf package to console app to be able to install it as windows service.
所以你会得到:
- 构建和部署WCF项目,您可以在IIS中托管它;
- 构建一个控制台应用程序,您可以将其作为控制台应用程序运行;
- 使用topshelf install param,您可以将控制台应用程序安装为Windows服务。
这篇关于如何从Windows服务中公开restful接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!