Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未找到WCF命名管道终结点_C#_Wcf_Named Pipes - Fatal编程技术网

C# 未找到WCF命名管道终结点

C# 未找到WCF命名管道终结点,c#,wcf,named-pipes,C#,Wcf,Named Pipes,简单地说,我们需要通过WCF命名管道进行outproc通信。在开发工具中,客户端和服务组件都通过IOC在同一个可执行文件中实例化 服务主机: /// <summary> /// Default constructor /// </summary> public OpaRuntimeServiceHost(string serviceName, string hostAddress) { _serviceHost = new ServiceHost(typeof(O

简单地说,我们需要通过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();
}
//
///默认构造函数
/// 
公共OpaRuntimeServiceHost(字符串serviceName,字符串hostAddress)
{
_serviceHost=新的serviceHost(typeof(OpaRuntimeService),新的Uri[]{
新Uri(string.Format(“net.pipe://{0}/opa/{1}”、主机地址、服务名))
});
_serviceHost.AddServiceEndpoint(typeof(IOPARantimeService)、新NetNamedPipeBinding(NetNamedPipeSecurityMode.None)、serviceName);
_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))))
{

}
//
///默认构造函数
/// 
/// 
/// 
公共OpaRuntimeServiceClient(字符串serviceName、字符串hostAddress)
:base(新的ServiceEndpoint(ContractDescription.GetContract(typeof(IOParantimeService)),
新的NetNamedPipeBinding(NetNamedPipeSecurityMode.None),新的EndpointAddress(string.Format(“net.pipe://{0}/opa/{1}”,主机地址,serviceName)))
{
}
两者都已成功构建,但当客户端调用服务时,会生成以下错误:

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

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

环境包括Windows 10上的VS2015或Windows 7上的VS2012


我遗漏了什么吗?

我相信对AddServiceEndpoint的调用需要端点的地址(根据上下文)。在您的示例代码中,看起来您只传递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);
        }
    }
}

弄明白了。服务名称在服务主机设置中使用了两次,因此使用类似net的名称。pipe://localhost/opa/runtime/runtime 当它应该包含这个:net时。pipe://localhost/opa/runtime. 谢谢你的橡皮鸭子