【发布时间】:2013-04-15 16:57:26
【问题描述】:
我已经设置了一个系统,让工作进程完成一些工作,并与 GUI 进程和工作进程之间的命名管道进行协调。我在这里启动工作进程:
this.pipeGuidString = Guid.NewGuid().ToString();
var startInfo = new ProcessStartInfo(
"VidCoderWorker.exe",
Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture) + " " + this.pipeGuidString);
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
this.worker = Process.Start(startInfo);
// When the process writes out a line, its pipe server is ready and can be contacted for
// work. Reading line blocks until this happens.
this.logger.Log("Worker ready: " + this.worker.StandardOutput.ReadLine());
bool connectionSucceeded = false;
this.logger.Log("Connecting to process " + this.worker.Id + " on pipe " + this.pipeGuidString);
var binding = new NetNamedPipeBinding
{
OpenTimeout = TimeSpan.FromSeconds(10),
CloseTimeout = TimeSpan.FromSeconds(10),
SendTimeout = TimeSpan.FromSeconds(10),
ReceiveTimeout = TimeSpan.FromSeconds(10)
};
this.pipeFactory = new DuplexChannelFactory<IHandBrakeEncoder>(
this,
binding,
new EndpointAddress("net.pipe://localhost/" + pipeGuid + "/VidCoder"));
this.channel = this.pipeFactory.CreateChannel();
this.channel.Ping();
然后在工作进程内部:
host = new ServiceHost(
typeof (HandBrakeEncoder),
new Uri[]
{
new Uri("net.pipe://localhost/" + PipeGuidString)
});
host.AddServiceEndpoint(
typeof (IHandBrakeEncoder),
new NetNamedPipeBinding(),
"VidCoder");
host.Open();
encodeComplete = new ManualResetEventSlim(false);
Console.WriteLine("Service state is " + host.State + " on pipe " + PipeGuidString);
encodeComplete.Wait();
host.Close();
它在 100% 的时间里对大多数人(包括我)都有效。但是一位用户报告说,主机进程在尝试连接到工作进程时总是收到 EndpointNotFoundException,即使日志表明双方的 GUID 相同并且状态在工作进程。
我认为他的系统一定有一些不同的东西导致了失败,我想知道那可能是什么。
- 我已尝试通过远程桌面进行连接,但对我仍然有效。
- 我没有更改任何一个进程的强制完整性级别
- 我读了this answer,所以我要求用户运行
net localgroup "NETWORK USERS",但他不存在该组 - (编辑)Net.Pipe Listener Adapter 服务已为用户禁用,但在用户启用并启动后仍无法正常工作。
关于为什么会发生这种情况的任何其他想法?我阅读了一些有关本地与全局命名管道的内容,但由于我在本地进行通信并在本地生成进程,因此这似乎不是问题。
(edit2) 用户意外地能够获得 WCF 跟踪:http://engy.us/misc/TracesWithNetPipeStarted.svclog
(edit3) 它显然在以管理员身份运行主机进程时有效。是不是在这种情况下,管道通信的某些部分需要这些权限?如何设置管道通道,使其永远不需要管理员?
【问题讨论】:
-
可能是工作人员中未检测到的异常。您是否将所有内容都包含在带有异常日志记录的 try/catch 中?或者工作人员是否从一个任务中运行,而您在某个时间点不等待任务完成(这会丢失任务线程的异常)?
-
如in this answer 所述,Net.Pipe Listener Adapter 服务是否正在运行?另外,异常是否有 InnerException?
-
这一切都包含在一个带有日志记录的 try/catch 中。就工人而言,连接已准备好并正在工作。关于 Net.Pipe Listener Adapter 服务,当我的机器上一切正常时,我看不到它正在运行。关于 InnerException,我现在没有记录它,因为它是重试循环的一部分……它通常有有用的信息吗?
-
Net.Pipe Listener Adapter 已为用户禁用,但在启用并启动后仍无法正常工作。
-
您是否尝试启用 wcf 跟踪?
标签: c# wcf named-pipes