如何创建命名管道?

时间:2013-09-12 17:42:33

标签: c# named-pipes

我的静态方法中包含此代码:

PipeSecurity ps = new PipeSecurity();
ps.AddAccessRule(new PipeAccessRule(System.Security.Principal.WindowsIdentity.GetCurrent().Name, PipeAccessRights.FullControl | PipeAccessRights.CreateNewInstance, AccessControlType.Allow));

var xserver = new NamedPipeServerStream("XSocketsPipe", PipeDirection.In);
xserver.WaitForConnection();
IFormatter f = new BinaryFormatter();
var messageReceived = (Connection)f.Deserialize(xserver);
XSocketsData.User.Add(messageReceived);

现在,当我执行我的应用程序时,我得到“拒绝访问路径”。错误。我做错了什么?

1 个答案:

答案 0 :(得分:0)

NamedPipeServerStream实例必须双向声明,因此它看起来像是与构造函数相关的模糊M $错误消息。

请参阅此相关问题和答案: CallNamedPipe & NamedPipeServerStream, access denied?