无法远程访问 WCF 服务 [英] Cannot access WCF service remotely
问题描述
背景
我们在 Windows 服务中托管了一个 WCF Web 服务,该服务与 basicHttpBinding 一起运行.
We have a WCF web service hosted in a Windows Service running with the basicHttpBinding.
问题
浏览到本地机器上的服务 URL 工作正常,但尝试使用外部 IP 地址(远程或本地 EVEN)浏览不起作用.示例:
Browsing to the service URL on the local machine works fine, but trying to browse using the external IP address (either remotely or EVEN locally) does not work. Example:
http://localhost:8000/booking.svc
(OK)
http://
(不行)
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>
有人有什么想法吗?
推荐答案
尝试使用 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
代替.
This will allow the service to insert the URI you used to access the service in to the metadata so the wsdl aligns. Sometimes you'll go to access http://1.2.3.4/service.svc
but the metadata will reference http://localhost
. Locally that's fine, but remotely that makes grabbing the endpoint information impossible. Instead, now all those localhost
references will use 1.2.3.4
instead.
这篇关于无法远程访问 WCF 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!