未找到 WCF 命名管道端点

Posted

技术标签:

【中文标题】未找到 WCF 命名管道端点【英文标题】:WCF Named Pipes Endpoint not found 【发布时间】:2016-01-04 17:51:32 【问题描述】:

简单来说,我们需要通过 WCF 命名管道进行 outproc 通信。在开发工具中,客户端和服务组件都通过 IOC 在同一个可执行文件中实例化。

服务主机:

/// <summary>
/// Default constructor
/// </summary>
public OpaRuntimeServiceHost(string serviceName, string hostAddress)

    _serviceHost = new ServiceHost(typeof(OpaRuntimeService), new Uri[] 
        new Uri(string.Format("net.pipe://0/opa/1", hostAddress, serviceName))
    );
    _serviceHost.AddServiceEndpoint(typeof(IOpaRuntimeService), new NetNamedPipeBinding(NetNamedPipeSecurityMode.None), serviceName);
    _serviceHost.Open();

客户:

/// <summary>
/// Default constructor
/// </summary>
/// <param name="hostAddress"></param>
/// <param name="serviceName"></param>
public OpaRuntimeServiceClient(string serviceName, string hostAddress)
    : base(new ServiceEndpoint(ContractDescription.GetContract(typeof(IOpaRuntimeService)),
    new NetNamedPipeBinding(NetNamedPipeSecurityMode.None), new EndpointAddress(string.Format("net.pipe://0/opa/1", hostAddress, serviceName))))



两者都构造成功,但是当客户端调用服务时会产生这个错误:

在 net.pipe://localhost/opa/runtime 上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关详细信息,请参阅 InnerException(如果存在)。

不幸的是,没有内在的例外。根据其他问题,我确保 Net.Pipe Listener 服务正在运行。 Visual Studio 以提升的权限运行。

环境是 Windows 10 上的 VS2015 或 Windows 7 上的 VS2012。

我错过了什么吗?

【问题讨论】:

【参考方案1】:

我相信对 AddServiceEndpoint 的调用需要端点的地址(根据MSDN documentation)。在您的示例代码中,您似乎只传递了 serviceName。

我挖出了一些做类似事情的示例代码。但是,在我的示例中,我是从 ServiceHost 派生的:

public class CustomServiceHost : ServiceHost

    public CustomServiceHost() : base(
        new CustomService(),
        new[]  new Uri(string.Format("net.pipe://localhost/0", typeof(ICustomService).FullName)) )
    

    

    protected override void ApplyConfiguration()
    
        base.ApplyConfiguration();

        foreach (var baseAddress in BaseAddresses)
        
            AddServiceEndpoint(typeof(ICustomService), new NetNamedPipeBinding(), baseAddress);
        
    

【讨论】:

【参考方案2】:

想通了。服务名称在服务主机设置中使用了两次,因此当它应该包含以下内容时,请制作类似 net.pipe://localhost/opa/runtime/runtime 的内容:net.pipe://localhost/opa/runtime。谢谢你的橡皮鸭。

【讨论】:

以上是关于未找到 WCF 命名管道端点的主要内容,如果未能解决你的问题,请参考以下文章

WCF 服务命名管道故障

从 VB6 到 WCF 的命名管道

使用 App.Config 在 Windows 服务中的 WCF 命名管道

WCF 命名管道最小示例

带有命名管道的 WCF:如何允许并行调用?

WCF 命名管道错误:管道已结束。 (109, 0x6d)