WCF Windows Service Deployment

1 Dec

I recently started work on a personal project to make a WCF Windows Service using the following tutorial: [1]. I soon realised that I would need to write a batch file to not be hugely disadvantaged by manual deployment. I also wanted my deployment batch scripts to be re-useable by other developers on the project.

The batch files I came up with were:

Install.bat:

@ECHO OFF

:: Known issues –
:: 1) if services window is open (ie the one when u start->run->services.msc) then the process will not close. You must close this window.
:: 2) if you don’t do a clean build then it will just install old version of service. Make sure you uninstall then do a clean build.

cd..

SET projectDirectory=%CD%

cd /d “%WinDir%\Microsoft.NET\Framework\v4.0.*”

SET net4Path=%CD%

@ECHO ON

%net4Path%\installutil “%PROJECTDIRECTORY%\bin\Debug\OrderServices.exe”

net start OrderServices

Uninstall.bat:

REM @ECHO OFF

cd..

SET projectDirectory=%CD%

cd /d “%WinDir%\Microsoft.NET\Framework\v4.0.*”

SET net4Path=%CD%

net stop OrderServices

%net4Path%\installutil /u “%PROJECTDIRECTORY%\bin\Debug\OrderServices.exe”

pause

Reinstall.bat (untested):

@echo off
CALL Unistall.bat
CALL Install.bat

Those batch files assume the following file structure in your service project:

ProjectStructure

Update:

The following link adds reference information as to how to forcefully play with services with the SC command: http://ss64.com/nt/sc.html

Leave a comment