1. Create a Windows service
2. Add the Installer
3. Modifications
4. Delete the main function of the Proman.CS that comes with it
5. Modify services to add 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. Create a service Interface
Namespace Handpickmatchservices
{
[ServiceContract (Namespace = "Handpickmatchservices", ConfigurationName = "
Imatcher")]
Interface Imatcher
{
[OperationContract]
Task domatchingredient (list<string> ingredients);
}
}
7. Create a service Instance
Namespace Handpickmatchservices
{
public class Matcher : Imatcher
{
Public async Task Domatchingredient (list<string> ingredients)
{
}
}
}
8. Add Configuration <system.serviceModel>
<configSections>
<section name= "log4net" type= "log4net. Config.log4netconfigurationsectionhandler, log4net "/>
</configSections>
<system.serviceModel>
<services>
<!--This section are optional with the new configuration model
Introduced in. NET Framework 4. -
<service name= "Handpickmatchservices.matcher"Behaviorconfiguration="Matcherbehavior">
<baseAddresses>
<add baseaddress= "Net.pipe://localhost/notification/service"/>
</baseAddresses>
<!--This endpoint are 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" MaxR Eceivedmessagesize= "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.
Enter CD C:\Windows\Microsoft.NET\Framework\v4.0.30319 carriage return
To switch the current directory, it is important to note that in the C:\Windows\Microsoft.NET\Framework directory there are many similar versions, specifically to which directory to see the project's operating environment, for example, the result is. NET framework2.0 need to input 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
Create Windows Service base on Net.pipe, Windows services