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