2013-01-03 34 views
1

我面臨的一個奇怪的問題與Windows服務到Windows窗體通信基礎WCF的無終點命名管道服務(通知托盤)應用程序中使用WCF基於命名管道的終點。(.NET Framework 4.0中)具體應用

安裝完成後,服務會正確地將消息發送到我的winform(通知托盤)應用程序,並按預期工作。

但是,一旦我重新啓動機器。該服務無法找到Namedpipe端點。我嘗試通過從VS 2010創建另一個應用程序來發送消息,並且它能夠將消息發送到我的Windows窗體(Notification Tray)應用程序。

的Windows服務引發的例外是

There was no endpoint listening at net.pipe://localhost/Pipe/Pipe1 that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. 
Error innerException : System.IO.PipeException: The pipe endpoint 'net.pipe://localhost/Pipe/Pipe1' could not be found on your local machine. 
Error stackStrace : Server stack trace: at System.ServiceModel.Channels.PipeConnectionInitiator.GetPipeName(Uri uri, IPipeTransportFactorySettings transportFactorySettings) at System.ServiceModel.Channels.NamedPipeConnectionPoolRegistry.NamedPipeConnectionPool.GetPoolKey(EndpointAddress address, Uri via) at System.ServiceModel.Channels.CommunicationPool`2.TakeConnection(EndpointAddress address, Uri via, TimeSpan timeout, TKey& key) at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout) at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at NamedPipe.Communication.IPipeService.PipeIn(String data) at NamedPipe.Sender.SendMessage(String messages, String PipeName) at NamedPipe.Sender.SendMessage(String messages). 
+0

你的winform應用程序正在運行嗎? – Paparazzi

+0

是的,我的winform應用程序正在運行,它也出現在托盤圖標中。它還顯示通知氣球,當從控制檯應用程序或其他應用程序中擊中命名管道時(在機器重新啓動時,即Windows服務無法通信時)。 –

回答

2

我想認爲,這個問題關於有安全上下文。在安裝環境「SYSTEM」下運行的服務可以在安裝安裝後立即找到「命名管道」服務的端點,因爲安裝程序通過UAC彈出窗口提升了它的權限,從而運行Windows服務和WinForm(命名管道主機)應用程序在相同的安全上下文中,因此找到了端點。重新啓動後,雖然Winform應用程序在登錄用戶安全上下文下,但該服務仍處於相同的安全上下文環境中,導致「NamedPipe」被託管在與該服務分開的安全上下文中。並且該服務試圖找到落入其安全上下文中的端點,而這一次並非如此。因此「未找到端點」異常。