create windows service base on net.pipe ,windows 服务
2016-05-06 13:56
716 查看
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
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
相关文章推荐
- 选择恐惧症的福音!教你认清MVC,MVP和MVVM
- java 有用的东西
- JavaScript中的原型(prototype)和闭包(closure)(转)
- Android—自定义标题栏的实现及遇见的问题解决
- CentOS系统时间与现在时间相差8小时解决方法
- 169. Majority Element
- ListViewItem获取不到焦点
- 设计模式之简单工厂模式
- Android 手势检测实战 打造支持缩放平移的图片预览效果(下)
- cf350div2ABCD1D2E
- PHP自学no00009数据类型浮点型之圆周率输出
- Android让Fragment加载到Activity中
- codeforces 350 div2 C. Cinema map标记
- Java与WCF交互(一):Java客户端调用WCF服务 【转】
- android studio无法关联源码
- Codeforces Round #350 (Div. 2)easy
- Java中传值和传引用
- leetcode 61 --Rotate List 链表 循环/断开 翻转
- 2014 年最热门的国人开发开源软件 TOP 100
- C++ 运算符重载