【发布时间】:2014-02-03 06:11:00
【问题描述】:
我的团队有一个用 .NET 4.0 编写的小型 WCF Rest 服务。从历史上看,它已部署在运行 IIS 7 的 Server 2008 机器上,使用以下绑定配置:
<bindings>
<webHttpBinding>
<binding name="httpsBinding">
<security mode="Transport"/>
</binding>
</webHttpBinding>
</bindings>
正如人们所期望的那样,该服务可以很好地使用 HTTP 或 HTTPS,只要 Web 服务器配置了每个绑定。
但是,当我们在运行 IIS 8 的 Server 2012 机器上安装该服务时,该服务将通过 HTTPS 正常工作,但通过 HTTP 的请求失败并显示 404 状态。
我们查看了 Server 2008 和 Server 2012 机器的 IIS 配置,但没有什么是明显的罪魁祸首。所有的设置似乎都是一样的。
是否需要在 IIS 或 Web 配置中进行任何额外的配置? SO和MSDN上有很多关于使用HTTP而不是HTTPS的服务的问题,但我没有看到相反的问题。
编辑:
根据 WCF 跟踪日志,2008 机器在 HTTP 和 HTTPS 上打开端点侦听器,而 2012 机器只为 HTTPS 打开端点侦听器。
为了确保我没有遗漏服务本身的任何内容,我在两台机器上都安装了相同的 MSI,甚至用 2008 机器上的那个重写了 2012 机器上的 web.config(尽管他们应该有反正是一样的)。行为没有变化。
编辑 2:
以下是完整的 web.config:
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="None"/>
<compilation targetFramework="4.0"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service name="service1">
<endpoint behaviorConfiguration="webHttp" binding="webHttpBinding" bindingConfiguration="httpsBinding" contract="service1"/>
</service>
<service name="service2">
<endpoint behaviorConfiguration="webHttp" binding="webHttpBinding" bindingConfiguration="httpsBinding" contract="service2"/>
</service>
<service name="service3">
<endpoint behaviorConfiguration="webHttp" binding="webHttpBinding" bindingConfiguration="httpsBinding" contract="service3"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="httpsBinding">
<security mode="Transport"/>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
【问题讨论】:
-
您只向我们展示了您在客户端收到的 404,而您应该从服务器端对此进行诊断。您的 IIS 日志说明了错误的确切原因是什么? WCF 跟踪告诉您什么消息是否最终进入 WCF 管道?非 WCF 请求是否适用于同一个应用程序?
-
HTTP 状态 404 代码通常意味着您正在使用的 URL 无法映射到服务操作。如果出现身份验证错误,您将收到 403。尝试enabling WCF tracing 以确保 HTTP 请求通过 IIS 到达 WCF 管道。
-
能否请您展示其余的服务配置。
标签: wcf wcf-binding iis-8