Question

So I have a windows service running as Local System.

this windows service then starts off a WCF service.

From my machine there is no problem and works fine.
From a test console application, on the target machine, it works fine
From a windows service, on the target machine, it does not work. Nor does it throw an exception...

I am really stuck on this. :(

Could this be permissions?

m_tknCancelToken = new CancellationTokenSource();

/**************************************************************************************/
/***  Create and start the task                                                     ***/
/**************************************************************************************/

m_tskService = Task.Factory.StartNew((object o) => 
{
    RunService();
}, 
m_tknCancelToken);

/**************************************************************************************/
/***  Set the handler when the task is cancelled or faulted                         ***/
/**************************************************************************************/

m_tskService.ContinueWith(
    TaskEndedHandler, 
    TaskContinuationOptions.OnlyOnFaulted);

m_tskService.ContinueWith(
    TaskEndedHandler,
    TaskContinuationOptions.OnlyOnCanceled);

and then to catch the errors.

private void TaskEndedHandler(Task tskTask)
{
    Log.Log(String.Format("{0} has ended", ServiceName), "WHS010CI");

    if (tskTask.Exception != null)
    {
        Log.LogEx(tskTask.Exception, "WHS0103E");

        if (tskTask.Exception.InnerExceptions != null)
        {
            foreach (Exception ex in tskTask.Exception.InnerExceptions)
            {
                Log.LogEx(ex, "WHS0104E");
            }
        }
    }

    if(tskTask.IsCanceled)
    {
        Log.Log(String.Format("[{0}] has been cancelled", ServiceName), "WHS0104W");
    }
}
Was it helpful?

Solution

As usual it was a stupid mistake.

In my console application I was binding an SSL certificate to a port, this was removed as the powers that be did not want this in production code, which is understandable. So I removed it to then have a seperate batch file or otherwise which has to be manually run... however this is what I forgot to do. :(

for those that are interested, below is the code from my test app.

process = new Process();
process.StartInfo = BindCertToPort(port, certificate);
process.Start();

method:

private static ProcessStartInfo BindCertToPort(int iPort, X509Certificate2 certificate, bool bRemove = false)
{
    string strAction = null;
    string strExtraArguments = null;

    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "netsh.exe");

    if (bRemove)
    {
        strAction = "delete";
    }
    else
    {
        strAction = "add";
        strExtraArguments = string.Format(" certhash={0} appid={{{1}}}", certificate.Thumbprint, Guid.NewGuid());
    }

    startInfo.Arguments = string.Format("http {0} sslcert ipport=0.0.0.0:{1}{2}", strAction, iPort, strExtraArguments);
    startInfo.RedirectStandardOutput = true;
    startInfo.UseShellExecute = false;
    startInfo.CreateNoWindow = true;

    return startInfo;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top