2011-04-06 103 views
1

我正在開發使用.Net框架版本3.5的Windows服務。它需要在遠程計算機上調用Web服務,並且遇到奇怪的安裝問題。作爲用戶安裝Windows服務失敗

我曾經在我的機器上安裝它作爲User(默認),並在系統提示時提供了我的登錄名和密碼,並且一切正常。然後在某個時候,它停止工作,我發現將它安裝爲LocalSystem,並且工作正常。

現在我試圖調用遠程Web服務,我收到來自WCF錯誤:

There was no endpoint listening at https://www.remote.com/webservice.asmx that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. 

顯然,這可能是由於運行的服務爲LocalSystem(不具有互聯網訪問):There was no endpoint listening at <URI> that could accept the message. This is often caused by an incorrect address or SOAP action

所以,我試着切換回安裝服務User並提供我的憑據(我應該注意在這一點上,我是我的機器的管理員)。但它不工作,和錯誤消息(和InstallUtil日誌文件的內容)都沒有什麼功效:

Running a transacted installation. 

Beginning the Install phase of the installation. 
See the contents of the log file for the Service.exe assembly's progress. 
The file is located at Service.InstallLog. 

An exception occurred during the Install phase. 
System.InvalidOperationException: An exception occurred in the OnAfterInstall event handler of System.ServiceProcess.ServiceInstaller. 
The inner exception System.InvalidOperationException was thrown with the following error message: Service ServiceName was not found on computer '.'. 
The inner exception System.ComponentModel.Win32Exception was thrown with the following error message: The specified service does not exist as an installed service. 

The Rollback phase of the installation is beginning. 
See the contents of the log file for the Service.exe assembly's progress. 
The file is located at Service.InstallLog. 

The Rollback phase completed successfully. 

The transacted install has completed. 

至於我可以告訴相關的一點是,該服務無法安裝。沒有更多信息!任何想法爲什麼服務可能成功安裝爲LocalSystem,但作爲User作爲Administrators組成員安裝時安裝失敗?

回答

1

嘗試使用NetworkService用戶。 出於安全原因,LocalService不允許與外部世界建立連接。

至於你無法自己安裝服務的原因,這可能是由於UAC。我發現,除非UAC完全關閉,否則即使您是帳戶的管理員,也無法安裝服務。這是因爲您的帳戶沒有此特權。我相信你可以通過組策略管理器來解決這個問題。

+0

嘗試安裝爲NetworkService會在帶有消息的OnAfterInstall中引發Win32Exception:訪問被拒絕。 – 2011-04-06 11:13:51

+0

我應該澄清:我的意思是作爲NetworkService用戶_run_服務。您需要以具有特殊權限的用戶身份進行安裝。 UAC是否在此機器上處於活動狀態? – 2011-04-06 11:21:51

+0

@Jonas:是的,這是一個Windows 7的盒子,所以我認爲UAC正在被使用。我在Visual Studio命令提示符下運行InstallUtil(我以'以管理員身份運行'打開)。我之前的評論(安裝爲NetworkService)並不完全正確,我的意思是ServiceProcessInstaller的Account屬性(即它將運行的帳戶)被設置爲NetworkService。還值得注意的是它被設置爲自動啓動(儘管我將它設置爲手動啓動時遇到了相同的問題)。 – 2011-04-06 11:34:19