Richard210363
Richard210363

Reputation: 8406

How do I set permissions for a WCF Windows Service?

I have a Windows service that exposes a WCF service.

I also have an application that talks to the WCF service and sends commands and receives data back.

All this works fine when I run the application from Visual Studio.

However, when I install the application and run it, the application cannot communicate with the service. Nor can the batch files that the application runs to Stop and Start the service.

I've tried using netsh to 'reserve' the URI but I don't really know what I'm doing :-)

Can you point me in the right direction?

Windows Server code WCF Service code (abridged):

// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "WCF_Service" in both code and config file together.
[ServiceContract]
public class InternetGauge_IO
{

    [OperationContract]
    public void Pause()
    {
        RunningState.paused = true;
    }

    [OperationContract]
    public void Continue()
    {
        RunningState.paused = false;
    }

    [OperationContract]
    public bool GetRunningState()
    {
        return RunningState.paused;
    }
    ....

Windows Server code WCF Create endpoint code:

        private void InitializeConsoleComms()
    {
        try
        {
            //Prepare comms with the Console application
            Type serviceType = typeof(InternetGauge_IO);
            host = new ServiceHost(serviceType, new Uri[] { new Uri("http://localhost:8080/") });

            // Add behavior for our MEX endpoint
            ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
            behavior.HttpGetEnabled = true;
            host.Description.Behaviors.Add(behavior);

            // Create basicHttpBinding endpoint at http://localhost:8080/RJB.InternetGauge/
            host.AddServiceEndpoint(serviceType, new BasicHttpBinding(), "RJB.InternetGauge");

            // Add MEX endpoint at http://localhost:8080/MEX/
            host.AddServiceEndpoint(typeof(IMetadataExchange), new BasicHttpBinding(), "MEX");

            host.Open();
            logger.LogEvent("Console comms ready", "Internet Gauge", 4, 1);
        }
        catch (Exception e)
        {
            logger.LogEvent("Failed to open Console comms", "Internet Gauge", 1, 1);
            logger.LogEvent("Exception : " + e.InnerException + " Stack Trace: " + e.StackTrace + " Message: " + e.Message, "RJB.InternetGauge.WindowsService.Main", 1, 1);
        }
    }

The application just uses the generated proxy and methods e.g.

private bool GetRunningState()
    {
        try 
        {           
            InternetGauge_IOClient client = new InternetGauge_IOClient();
            isRunning = true;
            return(client.GetRunningState());
        }
        catch (Exception)
        {
            trayIcon.Text = "Internet Gauge Windows Service does not appear to be running.";
            trayIcon.Icon = RJB.InternetGauge.Console.Properties.Resources.ServiceStopped;
            isPaused = true;
            isRunning = false;

            return isPaused;
        }
    }

The netsh command I tried

netsh http add urlacl url=http://+:8080/InternetGauge_IO user=PC-01\richard

Any ideas?

Thanks Richard

Upvotes: 0

Views: 1622

Answers (1)

Richard210363
Richard210363

Reputation: 8406

It is because I am a twit.

Didn't copy the app.config over during the installation program.

All works fine now.

Upvotes: 1

Related Questions