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

时间:2020-10-13 22:17:45

标签: c# docker wcf named-pipes

我一直试图在本地连接到运行命名管道控制台应用程序的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

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

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

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

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

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