locked
Multiple WCF Services referencing the same Executable RRS feed

  • Question

  • Hi. I have a WCF service which is being hosted as a Windows Service. I'm using InstallUtil.exe to install the service similar to :

    InstallUtil.exe /Project=Project1 C:\MyService.exe

    I need to have multiple services using the same executable, so I'm picking up the 'Project' command line argument and using it to change the service name :

    public ProjectInstaller()
    {
        String[] args = Environment.GetCommandLineArgs();
        InstallContext tmp_ctx = new InstallContext(null, args);
        project = tmp_ctx.Parameters["Project"];
    
        service = new ServiceInstaller();
        service.ServiceName = "MyProjectService_" + project;
        
        Installers.Add(service);
    }
    

    This all works fine and I can get multiple services running (MyProjectService_Project1, etc.). The problem is that I can't uninstall them using InstallUtil

    If I run "InstallUtil.exe -u C:\MyService.exe" - it gives me an error saying that The Specified Service (MyProjectService) does not exist as an installed Service. Presumably, it must still have a reference to the name of the service before I renamed it? Is there anyway I can get this to uninstall cleanly? using a custom Uninstall method maybe? Thanks

    Monday, July 12, 2010 5:07 PM

Answers

  • OK - managed to resolve this now. I've overriden the Uninstall method and used a TransactedInstaller, which allows me to specify the properties (i.e. the name) of the service I want to install :

    TransactedInstaller ti = new TransactedInstaller();
    ServiceInstaller si = new ServiceInstaller();
    
          si.ServiceName = "MyProjectService_Project1"; 
          ti.Installers.Add(si);
    
          string path = string.Format("/assemblypath={0}", System.Reflection.Assembly.GetExecutingAssembly().Location);      
          string[] cmdline = new string[] { path };
    
          InstallContext ctx = new InstallContext("", cmdline);
    
          ti.Context = ctx;
    
          //Uninstall
          ti.Uninstall(null);
    • Marked as answer by DeeksUK Tuesday, July 13, 2010 12:05 PM
    Tuesday, July 13, 2010 12:05 PM

All replies

  • Moved to the setup and deployment thread since the service here is installer and not WCF
    Sajay
    Monday, July 12, 2010 7:27 PM
  • Hi DeeksUK,

     

    After you install the app do you see the entry in Control Panel -> Programs and Features list? If the entry is there, can you remove the app from there?

     

    Sincerely,

    Kira Qian

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    Tuesday, July 13, 2010 8:45 AM
  •  

    Hi. Unfortunately, it doesn't appear in Add/Remove Programs. Ideally, I'd like to remove it programmatically. I currently looking into whether I can use the TransactedInstaller (System.Configuration.Install) to remove it. Thanks

    Tuesday, July 13, 2010 8:50 AM
  • OK - managed to resolve this now. I've overriden the Uninstall method and used a TransactedInstaller, which allows me to specify the properties (i.e. the name) of the service I want to install :

    TransactedInstaller ti = new TransactedInstaller();
    ServiceInstaller si = new ServiceInstaller();
    
          si.ServiceName = "MyProjectService_Project1"; 
          ti.Installers.Add(si);
    
          string path = string.Format("/assemblypath={0}", System.Reflection.Assembly.GetExecutingAssembly().Location);      
          string[] cmdline = new string[] { path };
    
          InstallContext ctx = new InstallContext("", cmdline);
    
          ti.Context = ctx;
    
          //Uninstall
          ti.Uninstall(null);
    • Marked as answer by DeeksUK Tuesday, July 13, 2010 12:05 PM
    Tuesday, July 13, 2010 12:05 PM