如果只是寄宿单个wcf服务,方法很简单,步骤:
1、创建好一个windows服务。关于windows服务内容见:http://www.cnblogs.com/zhaow/p/7866916.html
2、在windows服务的OnStart、OnStop方法中,寄宿服务。实现参考如下:

namespace MyWindowsServiceHost
{
public partial class MyServiceHost : ServiceBase
{
private ServiceHost myHost = new ServiceHost(typeof(MyService));
public MyServiceHost()
{
InitializeComponent();
} protected override void OnStart(string[] args)
{
myHost.Open();
} protected override void OnStop()
{
myHost.Close();
}
}
}

3、将WCF相关配置copy到windows服务的app.config中。
4、写一个用于安装和卸载windows服务的bat文件,如:

@echo off
set /p var=是否要安装 WCF 服务(Y/N):
if "%var%" == "y" (goto install) else (goto batexit) :install
copy C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe InstallUtil.exe /Y
call InstallUtil.exe WindowsService.exe
pause :batexit
exit //卸载 @echo off
set /p var=是否要卸载 WCF服务(Y/N):
if "%var%" == "y" (goto uninstall) else (goto batexit) :uninstall
copy C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe InstallUtil.exe /Y
call InstallUtil.exe /u WindowsService.exe
pause :batexit
exit

5、关于.bat批处理文件
新建一个.txt,把代码copy进去,再把扩展名改成.bat。批处理文件要放到Windows服务程序生成的exe同级目录下。

注意32位系统和64位系统的区别:
32位操作系统:

@echo off
set /p var=是否要安装 WCF 服务(Y/N):
if "%var%" == "y" (goto install) else (goto batexit) :install
copy C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe InstallUtil.exe /Y
call InstallUtil.exe MyWindowsServiceHost.exe
call sc start "MyServiceHost"
pause :batexit
exit

64位操作系统:

@echo off
set /p var=是否要安装 WCF 服务(Y/N):
if "%var%" == "y" (goto install) else (goto batexit) :install
copy C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe InstallUtil.exe /Y
call InstallUtil.exe MyWindowsServiceHost.exe
call sc start "MyServiceHost"
pause :batexit
exit

如果是在x86平台下生成的Windows服务安装程序,即使是在64位操作系统下,也需要使用32位下的批处理文件。

接下来,测试下服务的安装与卸载:

安装卸载测试

安装

右键service_install.bat,以管理员身份运行

输入y,回车

查看系统服务,已成功安装

卸载

右键service_uninstall.bat,以管理员身份运行

输入y,回车

查看系统服务,已成功卸载

本文参考:
http://blog.csdn.net/doris_d/article/details/46739193
https://www.cnblogs.com/stulife/archive/2011/04/14/2016118.html
https://www.cnblogs.com/seekdream/p/6821348.html

WCF寄宿windows服务一的更多相关文章

  1. WCF寄宿windows服务二

    如果有很多WCF服务需要寄宿,需要额外做一些工作:总体思路是:先把这些WCF服务的程序集打包,然后利用反射加载各个WCF服务的程序集,按顺序一个一个寄宿.先来看看我们需要寄宿的WCF服务: 实现步骤: ...

  2. 微软 WCF的几种寄宿方式,寄宿IIS、寄宿winform、寄宿控制台、寄宿Windows服务

    WCF寄宿方式是一种非常灵活的操作,可以在IIS服务.Windows服务.Winform程序.控制台程序中进行寄宿,从而实现WCF服务的运行,为调用者方便.高效提供服务调用.本文分别对这几种方式进行详 ...

  3. WCF服务自我寄宿 Windows服务

    WCF寄宿有自我寄宿跟IIS寄宿 服务代码: [ServiceContract] ---服务契约 public interface ICustomerService { [OperationContr ...

  4. WCF 寄宿Windows以及控制台启动

    一:添加windows服务 二:修改XXXInstaller1的StartType=Automatic,修改ProcessInstaller1的Account=LocalSystem 三:在progr ...

  5. WCF安装Windows服务

    安装图解: 安装命令: 1. 开始 ->运行 ->cmd2. cd到C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319(Framework版本号按I ...

  6. C#.NET 操作Windows服务承载WCF

    Windows服务的制作.安装可以参考这篇: C#.NET 操作Windows服务(安装.卸载) - runliuv - 博客园 (cnblogs.com) 本篇会在这个解决方案基础上,继续修改. 一 ...

  7. 编写寄宿于windows服务的WCF服务

    由于业务中有些任务需要在后台静默长期运行,或者有些服务队响应的要求比较苛刻,这样的WCF服务就不适合寄宿于IIS中.IIS每隔一段时间w3wp进程会闲置超时,造成服务的运行停止,因此这种耗时或者定时任 ...

  8. 将WCF寄宿在托管的Windows服务中

    在我之前的一篇博客中我介绍了如何发布WCF服务并将该服务寄宿于IIS上,今天我再来介绍一种方式,就是将WCF服务寄宿在Windows服务中,这样做有什么好处呢?当然可以省去部署IIS等一系列的问题,能 ...

  9. WCF服务寄宿IIS与Windows服务 - C#/.NET

    WCF是Windows平台下程序间通讯的应用程序框架.整合和 .net Remoting,WebService,Socket的机制,是用来开发windows平台上分布式开发的最佳选择.wcf程序的运行 ...

随机推荐

  1. Java-JVM OutOfMemory 情况(JDK8)

    JVM 运行时内存结构(Run-Time Data Areas) 内存溢出分为两大类:OutOfMemoryError 和 StackOverflowError. 一.HeapOomError (JV ...

  2. js回调函数(callback)(转载)

    学习jquery时,对回调函数感觉很困惑,在晚上找了半天,忽然发现这篇文章很浅显,基本说明了问题.故转载 原文: 自学jquery的时候,看到一英文词(Callback),顿时背部隐隐冒冷汗.迅速go ...

  3. 【SQL】 java.sql.SQLException: You can't specify target table 'emp' for update in FROM clause

    在执行sql: delete from emp where id in (select id from emp where cdate<'2018-02-02') 时报出以下异常: ### Th ...

  4. springboot 底层 JackSon 的使用

    Jackson常用的注解使用和使用场景: 接下来我们在看一段代码,这段代码是常用注解在实体类User中的简单使用:package zone.reborn.springbootstudy.entity; ...

  5. 3.创建一个pod应用

    创建一个应用:k8s增删查改: pod创建:kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1 [roo ...

  6. python之scrapy爬取jingdong招聘信息到mysql数据库

    1.创建工程 scrapy startproject jd 2.创建项目 scrapy genspider jingdong 3.安装pymysql pip install pymysql 4.set ...

  7. 一个伪静态与404重定向例子(房产网),.htaccess文件内容

    ErrorDocument 404 /404.phpRewriteEngine OnRewriteBase /RewriteRule ^(.*)\.(asp|aspx|asa|asax|dll|jsp ...

  8. Jedis的Publish/Subscribe功能的使用

    redis内置了发布/订阅功能,可以作为消息机制使用.所以这里主要使用Jedis的Publish/Subscribe功能. 1.使用Spring来配置Jedis连接池 <!-- pool配置 - ...

  9. Dubbo架构与底层实现

    一.Dubbo的设计角色 (1)系统角色Provider: 暴露服务的服务提供方.Consumer: 调用远程服务的服务消费方.Registry: 服务注册与发现的注册中心.1Monitor: 统计服 ...

  10. 基于osgQt将OSG嵌入到Qt窗口中(有错误)

    1, 编译OSG 由于重装了win10的系统,Qt也安装了最新版5.13,把之前OSG重新编译了一遍,过程与之前的一模一样. Windows7 + OSG3.6 + VS2017 + Qt5.11 2 ...