WCF registers Windows Service

Source: Internet
Author: User

WCF registers Windows Service

2014-06-14

WCF registers Windows Service

Return

In front of creating a simple WCF program, we hosted the WCF service into the host console project. Here's how to host a WCF service into a Windows service:

1. Delete the original host console project and then right-click on solution to create a new Windowservice project. Such as:


2. Add a reference to the Contracts Project, service project, and System.ServiceModel to the Myfirstwindowsservice project.

3. Rename the Class1.cs file in the Myfristwindowsservice project to HelloHost.cs and open the file with the following code:

4.hellohost.cs

5.hellohost.cs[design], right-click on the interface and choose Add Installer. At this point, a ProjectInstaller.cs file is automatically generated in the project.

6. Open Projectinstaller.cs[design], the design interface will appear:

7. Select ServiceInstaller1, open its Properties view (Ctrl w,p), and modify the properties. As shown in the following:

8. Then select ServiceProcessInstaller1, open its properties view, and modify the properties. such as: (the service account here can also be other.) )

9. Next we look at the Program.cs file in this project. The code is as follows:

10. After you have done this, add the server-side configuration file to the Myfirstwindowsservice project. This is also written in the previous section with the following code:

11. Now our catalogue of solution is like this: F6,build. Make sure build success.

12. Open the Bin/debug file for the Myfirstwindowsservice project. Right-click on the project, open folder in Windows Explorer. The Debug folder has the following files:

13. Copy the files from the entire debug folder and place them in a different directory. I put it in the C:\FirstService. Later, our registered Windows service will look for EXE files from this directory.

14. The following is to register. We use InstallUtil.exe to register (you can also use SC, of course). Open InstallUtil.exe in the directory for My computer is: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319. You can proceed from the command such as this directory, and then execute the installutil command. Visual Studio Tools can also be found in all programs, with Visual Studio command prompt. The command to execute the installation is InstallUtil C:\FirstService\MyFirstWindowsService.exe

15. After the success, you can find it in the Control Panel-"Management tools-" service.

 

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.