【发布时间】:2018-04-22 21:39:42
【问题描述】:
我在 Windows 服务中托管 HTTP WCFService,在本地网络中它可以正常工作,但如果客户端在另一个网络中并尝试使用公共 IP 连接将不起作用。
配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config
file must be added to the host's
app.config file. System.Configuration does not support config files for
libraries. -->
<system.serviceModel>
<services>
<service name="WCFService.ServiceBehavior">
<endpoint address="" binding="wsHttpBinding"
contract="WCFService.ServiceContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:80/WCFService/service/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
【问题讨论】:
-
可能是防火墙?
-
您正在显示服务器部分的 web.config。显示客户端的 web.config。
-
防火墙已禁用。如果我在服务器浏览器中访问localhost:80/WCFService/service 它可以工作,但如果我没有设置公共 IP。