1

我在使用基于 WCF 的命名管道端点 (.Net Framework 4.0) 与 Windows 窗体(通知托盘)应用程序进行通信时遇到了一个奇怪的问题。

安装设置后,该服务会正确地将消息发送到我的 winform(通知托盘)应用程序并按预期工作。

但是一旦我重新启动机器。服务找不到 Namedpipe 端点。我尝试通过从 VS 2010 创建另一个应用程序来发送消息,它能够将消息发送到我的 Windows 窗体(通知托盘)应用程序。

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).
4

1 回答 1

2

我想认为这个问题与安全环境有关。在安全上下文“SYSTEM”下运行的服务可以在安装程序安装后立即找到“命名管道”服务的端点,因为安装程序通过 UAC 弹出窗口提升其权限,从而运行 Windows 服务和 WinForm( Namedpipe Host ) 应用程序在相同的安全上下文下,因此找到了端点。重新启动后,尽管 Winform 应用程序位于登录用户的安全上下文中,但服务仍处于相同的安全上下文中,这导致“NamedPipe”托管在与服务不同的安全上下文中。并且该服务试图找到落入其安全上下文中的端点,但这次不是。因此例外。

于 2013-01-10T11:40:35.453 回答