【问题标题】:WCF Named Pipes Endpoint not found未找到 WCF 命名管道端点
【发布时间】: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。

我错过了什么吗?

【问题讨论】:

    标签: c# wcf named-pipes


    【解决方案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。谢谢你的橡皮鸭。

      【讨论】:

        猜你喜欢
        • 2011-09-11
        • 2015-04-08
        • 1970-01-01
        • 1970-01-01
        • 2021-08-22
        • 2011-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多