create windows service base on net.pipe ,windows 服务

1.创建一个windows服务

2.添加安装程序

3.修改

4.删除自带的Proman.CS 的MAIN函数

5.修改Services,添加ServiceModel.dll

public class NotificationWindowsService : ServiceBase

{

public ServiceHost serviceHost = null;

public NotificationWindowsService()

{

ServiceName = "WCFNotificationService";

//InitializeComponent();

}

public static void Main()

{

ServiceBase.Run(new NotificationWindowsService());

}

protected override void OnStart(string[] args)

{

log4net.Config.XmlConfigurator.Configure();

if (serviceHost != null)

{

serviceHost.Close();

}

serviceHost = new ServiceHost(typeof(Matcher));

// Open the ServiceHostBase to create listeners and start

// listening for messages.

try

{

serviceHost.Open();

}

catch (Exception ex)

{

}

}

protected override void OnStop()

{

if (serviceHost != null)

{

serviceHost.Close();

serviceHost = null;

}

}

private void InitializeComponent()

{

//

// NotificationWindowsService

//

this.ServiceName = "WCFNotificationService";

}

}

6.创建Service Interface

namespace HandPickMatchServices

{

[ServiceContract(Namespace = "HandPickMatchServices", ConfigurationName = "IMatcher")]

interface IMatcher

{

[OperationContract]

Task DoMatchIngredient(List<string> ingredients);

}

}

7.创建Service Instance

namespace HandPickMatchServices

{

public class Matcher : IMatcher

{

public async Task DoMatchIngredient(List<string> ingredients)

{

}

}

}

8.添加Configuration <system.serviceModel>

<configSections>

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>

</configSections>

<system.serviceModel>

<services>

<!-- This section is optional with the new configuration model

introduced in .NET Framework 4. -->

<service name="HandPickMatchServices.Matcher" behaviorConfiguration="MatcherBehavior">

<host>

<baseAddresses>

<add baseAddress="net.pipe://localhost/notification/service" />

</baseAddresses>

</host>

<!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/ServiceModelSamples/service  -->

<endpoint address="" binding="netNamedPipeBinding" contract="IMatch" bindingConfiguration="Custom.WSHTTPBinding.Configuration">

<identity>

<dns value="localhost" />

</identity>

</endpoint>

<endpoint address="mex" binding="mexNamedPipeBinding" contract="IMetadataExchange" />

</service>

</services>

<bindings>

<netNamedPipeBinding>

        <binding name="Custom.WSHTTPBinding.Configuration" transferMode="Streamed" maxBufferPoolSize="4194304" maxReceivedMessageSize="9223372036854775807">

<security mode="None" />

</binding>

</netNamedPipeBinding>

</bindings>

<behaviors>

<serviceBehaviors>

<behavior name="MatcherBehavior">

<serviceMetadata httpsGetEnabled="false" />

<serviceDebug includeExceptionDetailInFaults="true" />

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

add reference

net.pipe://localhost/crawler/service/mex

install service\

1.

输入 cd C:\Windows\Microsoft.NET\Framework\v4.0.30319 回车

切换当前目录,此处需要注意的是,在C:\Windows\Microsoft.NET\Framework目录下有很多类似版本,具体去哪个目录要看项目的运行环境,例 如果是.net framework2.0则需要输入 cd C:\Windows\Microsoft.NET\Framework\v2.0.50727

2.

Install:

InstallUtil.exe E:\TestApp\Winform\WinServiceTest\WinServiceTest\bin\Debug\WinServiceTest.exe

uninstall:

InstallUtil.exe /u E:\TestApp\Winform\WinServiceTest\WinServiceTest\bin\Debug\WinServiceTest.exe

http://www.cnblogs.com/sorex/archive/2012/05/16/2502001.html

时间: 2024-07-29 05:37:25

create windows service base on net.pipe ,windows 服务的相关文章

使用Windows Service Wrapper快速创建一个Windows Service 如nginx

前言 今天介绍一个小工具的使用.我们都知道Windows Service是一种特殊的应用程序,它的好处是可以一直在后台运行,相对来说,比较适合一些需要一直运行同时不需要过多用户干预的应用程序,这一类我们称之为"服务"吧 编写Windows Service其实是不难的,尤其是如果有Visual Studio的话.但是仍然是有不少童鞋觉得略显繁琐,同时,如果有一些其他的程序,我们只拿到一个exe,或者一个bat,但又想让他象服务一样运行,怎么办呢 答案就是可以使用如下的一个工具,它的名称就

使用Windows Service Wrapper快速创建一个Windows Service

前言 今天介绍一个小工具的使用.我们都知道Windows Service是一种特殊的应用程序,它的好处是可以一直在后台运行,相对来说,比较适合一些需要一直运行同时不需要过多用户干预的应用程序,这一类我们称之为"服务"吧 编写Windows Service其实是不难的,尤其是如果有Visual Studio的话.但是仍然是有不少童鞋觉得略显繁琐,同时,如果有一些其他的程序,我们只拿到一个exe,或者一个bat,但又想让他象服务一样运行,怎么办呢 答案就是可以使用如下的一个工具,它的名称就

WCF - Windows Service Hosting

WCF - Windows Service Hosting The operation of Windows service hosting is a simple one. Given below are the steps with requisite coding and screenshots that explain the process in an easy way. 在windows服务上托管wcf是一个简单的操作. Step-1: Now let’s create a WCF

C#创建一个Windows Service

Windows Service这一块并不复杂,但是注意事项太多了,网上资料也很凌乱,偶尔自己写也会丢三落四的.所以本文也就产生了,本文不会写复杂的东西,完全以基础应用的需求来写,所以不会对Windows Service写很深入. 本文介绍了如何用C#创建.安装.启动.监控.卸载简单的Windows Service 的内容步骤和注意事项. 一.创建一个Windows Service 1)创建Windows Service项目 2)对Service重命名 将Service1重命名为你服务名称,这里我

C#创建Windows Service(Windows 服务)基础教程

Windows Service这一块并不复杂,但是注意事项太多了,网上资料也很凌乱,偶尔自己写也会丢三落四的.所以本文也就产生了,本文不会写复杂的东西,完全以基础应用的需求来写,所以不会对Windows Service写很深入. 本文介绍了如何用C#创建.安装.启动.监控.卸载简单的Windows Service 的内容步骤和注意事项. 一.创建一个Windows Service 1)创建Windows Service项目 2)对Service重命名 将Service1重命名为你服务名称,这里我

有图形用户界面的Windows Service

内容目录 起因解决方案一.开发环境二.创建Windows Service三.创建Service控制窗体程序四.运行Service控制窗体程序总结 起因 在平时部署Windows Service时,通过命令行部署服务太费劲了,总想着有没有想桌面程序那样的方式,点个按钮就能完成所有操作的了.此想法由来已久,只是事情比较多,最近总算有时间了,在此想法的驱使下,最终有了这篇文章的诞生. 解决方案 一.开发环境 操作系统:Windows 10 X64开发环境:VS2013编程语言:C#.NET版本:.NE

C# 创建Windows Service(Windows服务)程序

本文介绍了如何用C#创建.安装.启动.监控.卸载简单的Windows Service 的内容步骤和注意事项. 一.创建一个Windows Service 1)创建Windows Service项目 2)对Service重命名 将Service1重命名为你服务名称,这里我们命名为ServiceTest. 二.创建服务安装程序 1)添加安装程序 之后我们可以看到上图,自动为我们创建了ProjectInstaller.cs以及2个安装的组件. 2)修改安装服务名 右键serviceInsraller1

Mysql——安装server错误:cannot create windows service

在安装到最后一步,点击”execute“按钮时,出现错误cannot create windows service for mysql.error:0 解决方法: 在桌面上找到“MyComputer“,右键选择“Manage”,然后选择”Service and Applications“,然后选择”services“,找到”MySQL“服务: 右键”Stop“此服务后.以管理员身份打开cmd:   输入命令:sc delete mysql 此命令是删除”MySQL“服务.刷新”services“

A basic Windows service in C++ (CppWindowsService)

A basic Windows service in C++ (CppWindowsService) This code sample demonstrates creating a basic Windows Service application in VC++ 下载 C++ (776.9 KB) 评级 (14) 已下载49,480 次 收藏夹添加到收藏夹 需要 Visual Studio 2008 上次更新日期2012/3/2 许可证 MS-LPL 共享      翻译结果 english