2017-07-07 138 views
0

我正在学习编写WCF服务,并且我正在阅读本书中的示例,逐步地编写了我的简单服务。服务在我的个人电脑和连接到本地网络的每台设备上都能正常工作。当我尝试从本地网络的“外部”连接时,如果无法看到服务(通过客户端应用程序(通过我写的和通过浏览器(MEX)))。

我的主人的app.config:
无法连接到本地网络以外的WCF服务

<system.serviceModel> 

     <services> 
     <service name="WCF_1_MagicEightBallService.MagicEightBallService" 
       behaviorConfiguration="MagicEightBallServiceMEXBehavior"> 

     <endpoint address="" 
        binding="basicHttpBinding" 
        contract="WCF_1_MagicEightBallService.IMagicEightBall"> 
     </endpoint> 

     <endpoint address="mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange"> 
     </endpoint> 

     <host> 
      <baseAddresses> 
      <add baseAddress="http://[my ip]:8080/MagicEightBallService"/> 
      </baseAddresses> 
     </host> 

     </service> 
     </services> 

     <behaviors> 
     <serviceBehaviors> 
      <behavior name="MagicEightBallServiceMEXBehavior"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <useRequestHeadersForMetadataAddress/> 
      </behavior> 
     </serviceBehaviors> 
     </behaviors> 

    </system.serviceModel> 

我的IP是我的外部IP,但我一直在使用的IP使用和不使用无线路由器,并用不同的端口尝试。

+1

除非您有商业互联网计划,否则您的ISP很可能会阻止大多数默认网络端口(25,80,80,80,443等)。 – Cameron

+0

@Cameron所以没有办法自己托管网络服务?可以托管IIS的帮助? – Bibipkins

+1

你可以在IIS中托管它,你只需要使用非默认端口。只需在... 10000和65535之间选择一个数字即可。 – Cameron

回答

0

所以,正如在评论中提到的卡梅隆,问题在于ISP阻止了我的端口。这个答案可能是题外话了一点点,但为大家类似的问题,在这里我所做的:

  1. 扫描开放的端口与基于控制台免费的实用工具“的nmap”带命令:
    NMAP target.hostname。 com
  2. 然后我用http://www.yougetsignal.com/tools/open-ports/(当然,您可以使用任何其他网站)重新检查所有带有“未知”服务的端口。他们都是开放的,并使用Windows命令:
    netstat -aon | find/i“listen”| find“port”
    我得到了正在使用它们的应用程序的PID。
  3. 我选择了我不需要运行的应用程序使用的端口,关闭它并将该端口用于承载我的WCF服务的网站的IIS服务器绑定。

它的工作,我可以通过我的外部IP地址远程访问。