0

Problem:
there is a test server on which I have a bunch of automated test scripts for testing a web application hosted on a separate application server. For the sake of full automation, I developed a C# application which plays the role of execution engine(called TAMS). Therefore right after each round of deployment, testers can let this application run and wait for the results (no more hands-on needed). But the final goal is to launch the application by the build server, right after a successful deployment.

So my approach is that:
build server(Jenkins) sends a REST request to the test server which hosts my application(execution engine) and my application will execute the test scripts and finally send back a summary to our build server. As all three servers(Build server, application server and test server) are physically separated, I came up with following implementation idea:

Implementation:
there is a Web API Self-Hosting using windows service, waiting for a REST(get) request including a parameter. Once it receives the request, it should launch an application(which has a UI) on the same machine. My UI application is not running, it is supposed to get woken up by the web API(as a windows service).

so my solution is taking following steps:

1) client enters the following sample URL:
http://myserver:8080/values/GetString/[ProjectName]

2) Web API Self-Hosting receives the request

3) ValuesController(GetString) is responsible to launch the windows application and passing the "projectName" value to it.

Everything is working except for launching the app(nothing happens by each call, although at client side I get the expected returned dummy message with no exception!). I am wondering maybe I'm missing the good practice of a process invocation inside a controller! p.s: In a regular windows application, I can launch my app successfully using the code inside the controller.

any help is highly appreciated!

here is the valuesController(ValuesController.cs):

using System;
using System.Web.Http;
using System.Web.Http.SelfHost;
using System.Diagnostics;

namespace WinService_TAMS_GatewayWebAPI
{
    public class ValuesController : ApiController
       {
         public string GetString(string projectName)
            {
               Process.Start(@"C:\myApp\bin\Debug\myApp.exe", projectName);
               return projectName + "got launched!";
            }
      }
}

here is the selfHost.cs content that acts as the Windows Service to be hosted:

public partial class SelfHost : ServiceBase
    {
        public SelfHost()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            var config = new HttpSelfHostConfiguration("http://localhost:8080");

            config.Routes.MapHttpRoute(
                name: "API",
                routeTemplate: "{controller}/{action}/{projectName}",
                defaults: new { projectName = RouteParameter.Optional }
                );
            HttpSelfHostServer server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();
   }

Edited: The account of serviceProcessInstaller is LocalSystem

  • Please edit the question to show the code inside `processStart`. Also, what user is your windows service executing as? Also, how do you know the process isn't launching? You could use PerfMon to determine whether it is being launched or not. – RB. Sep 22 '17 at 15:22
  • Are you expecting to see a UI for the application you are launching? If so - you won't. Windows Services can't launch UIs...(possibly not *technically* true, but easier to pretend it's true - it's not a thing you are going to want to be doing...) – RB. Sep 22 '17 at 15:28
  • @RB. thnx for pointing out, I edited the code... Process.Start() is the correct one, which is not user-defined method. – hamzeh karbasiyan Sep 23 '17 at 07:09
  • @RB.regarding the UI launching, that is exactly what I'm looking for! The whole idea is to wake up the target application by just a REST request, which made me think of the current solution (launching the app via a web API self-hosting as a windows service). Please let me know if there is a workaroud to launch the UI from win service or you a different solution in mind. TIA – hamzeh karbasiyan Sep 23 '17 at 07:10
  • Are you expecting the UI to open on the machine which called the web service, or the machine the web service is running on? – RB. Sep 23 '17 at 07:12
  • I am expecting the web API to open my app(with UI) on the same machine as web API is running as a windows service. – hamzeh karbasiyan Sep 23 '17 at 07:15
  • Do you have to *start* a new instance of the UI? If you merely had to make an already running UI react to the webservice being called, then that would be much better. Your UI would register with the Windows Service on startup, then the Service would send a message (through WCF or whatever messaging technology you want) to the UI whenever the webservice is triggered. – RB. Sep 23 '17 at 07:22
  • But I would suggest you edit your question to include your actual use-case (i.e. What are you trying to achieve, rather than how are you trying to achieve it - your question is a classic [XY Problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)) – RB. Sep 23 '17 at 07:24
  • @RB. I put the scenario in the first paragraph, but again I edited to explain the problem first, and then mention my approach. hope it conveys the actual problem. – hamzeh karbasiyan Sep 23 '17 at 07:57
  • No, you have explained what you want to do. You have not explained *why* you want to do it - what are you actually trying to achieve (i.e. What benefit do you want to realise)? There is almost certainly a better way to achieve what you want to do. – RB. Sep 23 '17 at 08:15
  • Because what you are trying to do is a Bad Idea™ – RB. Sep 23 '17 at 08:16
  • @RB. I got what you mean, hope now the real problem is clear. – hamzeh karbasiyan Sep 23 '17 at 09:49

0 Answers0