无法远程访问WCF服务

3

背景

我们有一个托管在Windows服务中,使用basicHttpBinding运行的WCF Web服务

问题

在本地计算机上浏览服务URL可以正常工作,但尝试使用外部IP地址进行浏览(无论是远程还是本地)都无法工作。例如:

http://localhost:8000/booking.svc(正常)

http://<external-IP>:8000/booking.svc(不正常)

APP.CONFIG

<system.serviceModel>

    <services>
      <service behaviorConfiguration="DefaultServiceBehavior" name="HotelManagementSystem.ServiceHost.BookingService">
        <endpoint address="" binding="basicHttpBinding" contract="HotelManagementSystem.ServiceHost.IBookingService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/booking.svc" />
          </baseAddresses>
        </host>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="DefaultServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

Anyone have any ideas?


防火墙?你在服务器上添加了8000端口的例外吗? - Anuraj
除了防火墙外,添加一个baseAddress="http://external-ip:8000/booking.svc"的条目是否允许您连接?(我使用useRequestHeadersForMetadataAddress非常成功) - Brad Christie
@Anuraj,客户告诉我端口8000已经打开。 - Matt
@Matt - 你能够 telnet 到 8000 端口吗?此外,你(或客户)可以检查事件查看器以查看是否有任何日志记录在其中吗? - Tim
@BradChristie,useRequestHeadersForMetadataAddress 的东西非常出色。谢谢!如果您将其添加为答案,我将很高兴将其标记为解决方案。 - Matt
1个回答

4

尝试使用 useRequestHeadersForMetadataAddress

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <useRequestHeadersForMetadataAddress />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

这将允许该服务将您用于访问该服务的URI插入到元数据中,以使wsdl对齐。有时,您会尝试访问http://1.2.3.4/service.svc,但元数据将引用http://localhost。在本地使用是可以的,但在远程使用时,这样做将使获取端点信息变得不可能。现在,所有这些localhost引用都将改为使用1.2.3.4


不错的技巧 - 我得把它传给我的队友。虽然不是我的问题,但这是一个非常有用的答案。 - Tim

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接