2011-09-11 45 views
0

我有一個公開WCF服務的Windows服務。如何設置WCF Windows服務的權限?

我也有一個應用程序與WCF服務通話併發送命令並接收數據。

當我從Visual Studio運行應用程序時,所有這些工作正常。

但是,當我安裝應用程序並運行它時,應用程序無法與服務進行通信。 應用程序運行的批處理文件也不能停止並啓動服務。

我使用Netsh「儲備」的URI,但我真的不知道我在做什麼:-)

你能指出我朝着正確的方向試過嗎?

Windows服務器代碼WCF服務代碼(有刪節):

// 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服務器代碼WCF創建端點代碼:

 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); 
     } 
    } 

應用程序只使用生成的代理和例如方法

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; 
     } 
    } 

netsh命令我試過

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

任何想法?

感謝 理查德

+4

你會得到什麼錯誤? –

+0

此外,請參閱http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts –

+0

什麼時候調用InitializeConsoleComms?它應該在服務啓動時調用,即OnStart()。它可能在調試中起作用的原因是因爲Visual Studio託管您的WCF服務而不是Windows服務? –

回答

1

這是因爲我是一個強烈抵制。

未在安裝程序中複製app.config。

現在所有的工作都很好。