Create Windows Service base on Net.pipe, Windows services

Source: Internet
Author: User
Tags log4net

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.