简体   繁体   English

无法从本地网络外部连接到WCF服务

[英]Can`t connect to WCF service from outside of my local network

I am learning to write WCF services and I wrote my simple service going step by step with example from book I am reading. 我正在学习编写WCF服务,并通过阅读的书中的示例逐步编写了简单的服务。 Service works fine on my PC and every device connected to my LOCAL network. 服务在我的PC以及连接到我的本地网络的所有设备上均能正常运行。 When I try to connect from "outside" of my local network if fails to see service (both via client app I wrote and via browser(MEX)). 当我尝试从本地网络的“外部”连接时,如果看不到服务(通过我编写的客户端应用程序和浏览器(MEX)),则无法访问。

My host app.config: 我的主机app.config:

    <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>

My ip is my external ip, but I have tried using ip with and without using wifi router and with different ports. 我的ip是我的外部ip,但是我尝试使用带和不带wifi路由器以及不同端口的ip。

So, as mentioned Cameron in the comments, problem was with ISP blocking my ports. 因此,正如Cameron在评论中提到的那样,问题在于ISP阻止了我的端口。 This answer might be a little bit off topic, but for everyone with similar problem, here what I did: 这个答案可能与主题无关,但是对于每个有类似问题的人,我在这里做了以下工作:

  1. scanned open ports with free console-based utility "nmap" with command: 使用基于控制台的免费实用程序“ nmap”使用以下命令扫描开放端口:
    nmap target.hostname.com nmap target.hostname.com
  2. then I rechecked all ports with "unknown" service with http://www.yougetsignal.com/tools/open-ports/ (you, of course, can use any other website). 然后我通过http://www.yougetsignal.com/tools/open-ports/ (您当然可以使用任何其他网站)重新检查了所有具有“未知”服务的端口。 They were all open and with Windows command: 它们都是打开的,并使用Windows命令:
    netstat -aon |find /i "listening" |find "port" netstat -aon |查找/ i“正在侦听” |查找“端口”
    I got PIDs of apps that were using them. 我得到了正在使用它们的应用程序的PID。
  3. I chose port used by app that I don`t need running, closed it and used that port for IIS server binding of website hosting my WCF service. 我选择了我不需要运行的应用程序使用的端口,将其关闭,并将该端口用于托管WCF服务的网站的IIS服务器绑定。

It worked and I could get remote access via my external IP address. 它起作用了,我可以通过我的外部IP地址进行远程访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM