微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决将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容器。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。