将WCF Windows命名管道与Docker容器一起使用

问题描述

我一直试图在本地连接到运行命名管道控制台应用程序的docker容器。我无法通过docker容器从本地计算机连接到命名管道。我在网上发现了这些片段,方法是在docker run中为命名管道声明音量,但是我对如何使它起作用感到困惑。以下是我使用的代码示例。

控制台应用程序入口点

        private static void Main(string[] args)
        {
                using (var host = new ServiceHost(new discoveryProxyService(),"net.pipe://localhost/testname"))
            {
                ServicediscoveryProxyEndpointConfigurator.Configure(host,endpointConfig);
                host.open();
            }
         }

我的Docker文件看起来像这样

FROM mcr.microsoft.com/dotnet/framework/wcf:4.7.2-windowsservercore-ltsc2019
SHELL ["powershell"]

RUN Install-WindowsFeature -name NET-WCF-Pipe-Activation45
RUN Install-WindowsFeature -name NET-WCF-TCP-Activation45
RUN Install-WindowsFeature -name NET-WCF-HTTP-Activation45

# Next,this Dockerfile creates a directory for your application
workdir WcfdiscoveryProxyTest

# copies the site you published earlier into the container.
copY WcfdiscoveryProxyTest/ .

# start WCFTcpsElfHost service process in container as entrypoint process.
ENTRYPOINT .\bin\Debug\WcfdiscoveryProxyTest.exe

我的Docker命令如下

docker build -t test:latest .
docker run -d -itd -v \\.\pipe\localhost\testname:\\.\pipe\localhost\testname test:latest

任何帮助将不胜感激

解决方法

恐怕你不走运。 WCF仅在同一台机器上支持命名管道...

[...] netNamedPipeBinding绑定,该绑定在同一台计算机上提供跨进程通信。命名管道无法在所有计算机上使用。

https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/netnamedpipebinding

(很可能)这也适用于Docker容器。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...