首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法连接到Docker容器中托管的WCF服务

无法连接到Docker容器中托管的WCF服务
EN

Stack Overflow用户
提问于 2017-05-15 23:12:35
回答 1查看 2K关注 0票数 2

我正在尝试运行一个在Docker容器中公开WCF服务的应用程序。

该应用程序是使用TopShelf构建的,因此它既可以作为Windows Service运行,也可以(在开发中)作为独立的控制台程序运行。

我遇到的问题是WCF测试客户端无法获取元数据。值得一提的是,应用程序在本地执行时工作正常。

以下是应用程序在本地运行时由WCF测试客户端生成的元数据文件

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_ITestWcfDocker" sendTimeout="00:05:00">
                    <security mode="None" />
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://localhost:9998/" binding="netTcpBinding"
                bindingConfiguration="NetTcpBinding_ITestWcfDocker" contract="ITestWcfDocker"
                name="NetTcpBinding_ITestWcfDocker" />
        </client>
    </system.serviceModel>
</configuration>

这是我用来构建容器的Dockerfile

代码语言:javascript
复制
FROM microsoft/dotnet-framework:4.6.2
RUN powershell -Command Add-WindowsFeature NET-WCF-HTTP-Activation45
WORKDIR app
COPY bin/Release/net461 .
EXPOSE 9998 9999
ENTRYPOINT ["EMG.Service.TestWcfDocker.exe"]

在构建项目之后,我使用以下命令构建容器

代码语言:javascript
复制
docker build -t emg/test-wcf:latest .

然后我使用以下命令启动一个容器

代码语言:javascript
复制
docker run -p 9998:9998 -p 9999:9999 -t emg/test-wcf

这是我在控制台日志上得到的输出

代码语言:javascript
复制
Configuration Result:
[Success] Name EMG.TestWcfDocker, [Success] DisplayName EMG TestWcfDocker, [Success] Description EMG TestWcfDocker, [Success] ServiceName EMG.TestWcfDocker
Topshelf v4.0.0.0, .NET Framework v4.0.30319.42000
2017-05-15 15:46:48.0700|DEBUG|WcfServiceHost|Adding NetTcpBinding endpoint for ITestWcfDocker at net.tcp://localhost:9998/
2017-05-15 15:46:48.1012|DEBUG|WcfServiceHost|Adding Metadata endpoint at http://localhost:9999/
2017-05-15 15:46:49.2207|INFO|EMG.TestWcfDocker.Program|Starting EMG.TestWcfDocker
The EMG.TestWcfDocker service is now running, press Control+C to exit.
2017-05-15 15:46:50.2675|INFO|EMG.TestWcfDocker.Program|EMG.TestWcfDocker started

一旦启动了容器,我就使用它来获取容器的IP

代码语言:javascript
复制
docker inspect -f="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" container-name

然后,我使用返回的IP通过WCF Test Client连接到服务,但收到以下错误消息

代码语言:javascript
复制
Error: Cannot obtain Metadata from http://172.19.111.72:9999/ If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://172.19.111.72:9999/    Metadata contains a reference that cannot be resolved: 'http://172.19.111.72:9999/'.    There was no endpoint listening at http://172.19.111.72:9999/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.    Unable to connect to the remote server    A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 172.19.111.72:9999HTTP GET Error    URI: http://172.19.111.72:9999/    There was an error downloading 'http://172.19.111.72:9999/'.    Unable to connect to the remote server    A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 172.19.111.72:9999

如果我使用localhost,我会得到一个类似的错误。

tl;dr:

我在Docker容器中有一个WCF服务,我无法从主机连接到它。

EN

回答 1

Stack Overflow用户

发布于 2018-02-14 22:44:36

因此,为了支持TCP托管,您需要这样做:

代码语言:javascript
复制
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

安装托管在IIS上的WCF服务所需的Windows组件

代码语言:javascript
复制
RUN Add-WindowsFeature NET-WCF-TCP-Activation45; \
Add-WindowsFeature NET-WCF-HTTP-Activation45; \
Add-WindowsFeature Web-WebSockets

为IIS上的默认网站启用net.tcp协议

代码语言:javascript
复制
RUN windows\system32\inetsrv\appcmd.exe set app 'Default Web Site/' /enabledProtocols:"http,net.tcp"

EXPOSE 808
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43982989

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档