我有一个WCF服务页面只通过SSL运行WebGets / WebInvokes - 它在我的本地计算机上工作正常(自签名证书)。但是,在生产中,我可以访问service.svc(并且它向我提供有关如何使用的消息)但service.svc / AnyRequest返回404.两个环境都托管在IIS 7.5中。
我启用了跟踪功能,服务甚至无法接收任何方法请求(例如service.svc / SomeRequest),但它处理service.svc
就好了。它也在https://computername.domain.net/path/service.svc
听 - 这是正常的吗?它通常应该指向https://publicfacing.com/path/service.svc
吗?
另请注意,生产服务器在IIS中托管多个站点。
以下是我的web.config的system.serviceModel部分。 SSLBehave是从here建议的。
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SSLBehave">
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="https" port="443"/>
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="UserManagement.ajaxAspNetAjaxBehavior">
<webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Wrapped" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="UserManagement.ajax" behaviorConfiguration="SSLBehave">
<endpoint address="" behaviorConfiguration="UserManagement.ajaxAspNetAjaxBehavior"
binding="webHttpBinding" bindingConfiguration="TransportSecurity" contract="UserManagement.ajax" />
</service>
</services>
</system.serviceModel>
答案 0 :(得分:13)
我首先要检查一些事情;
答案 1 :(得分:7)
每当我使用新开发的WCF Web服务访问404时,我所做的第一件事就是检查解释此类调用所需的处理程序映射,因为它通常是问题的原因。有几种方法可以解决这个问题,其中许多方法都需要手动执行ServiceModelReg.exe
控制台命令:这些无疑是有效的程序,但如果你的开发机器特别有问题,它们可能也无法工作或产生其他问题复杂的配置。我在下面提出的分辨率方法稍微长一点,但具有更安全和安全地解决问题的优点。
安装完成后,您应该能够运行WCF服务而不会再次发生404错误。
有关此特定问题以及如何解决此问题的其他信息,您还可以在我的博客上read this post。
答案 2 :(得分:6)
我遇到了同样的问题。根据我的阅读,默认情况下,WCF不是NT认证授权(或HTTPContext兼容)。
我必须在以下部分中将此添加到我的配置文件中以获取WCF服务web.config:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
你做了什么,加上这个:
在实际的服务类定义中,我必须添加:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class DataService : IDataDeliveryServiceContract
这解决了我的问题。
答案 3 :(得分:5)
您可以使用WsHttp绑定实现传输级安全性。见this article;在你的绑定中尝试这个替代:
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
文章提到你应该将绑定与端点联系起来。
答案 4 :(得分:5)
也许在你的RouteConfig.cs文件中添加以下行:
routes.IgnoreRoute("{resource}.svc/{*pathInfo}");
只要您的.svc文件位于应用程序的根目录中。
答案 5 :(得分:4)
正如您所提到的,您可以通过.svc扩展名service.svc
访问您的服务,但不能以REST格式service.svc/AnyRequest
访问您的服务,问题必须在routing integration中。
将此添加到您的web.config
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/>
</handlers>
</system.webServer>
在IIS 6中此错误的原因必须是Check that file exists
设置svc扩展,请确保“检查文件是否存在未选中”。有关详细信息,请参阅IIS Hosted Service Fails。
答案 6 :(得分:0)
为了帮助其他人陷入困境-可能您的服务名称不是fully qualified name,必须是它。
答案 7 :(得分:0)
web.config中的以下设置修复了HTTPS网站上的WCF .svc 404:
<webHttpBinding>
<!-- https -->
<security mode="Transport">
<transport clientCredentialType = "None" proxyCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
答案 8 :(得分:0)
我尝试了上述解决方案,安装 WCF 服务,确保 API 目录中有适当的权限以及其他一些事情。
虽然其中一些是问题,但对我来说还有一个上面没有提到的问题。
如果为整个服务器或给定站点启用了请求过滤,请确保 .svc 是受信任的文件扩展名,否则将被阻止。转到 IIS > 请求过滤。单击编辑功能设置。检查是否选中了“允许未列出的文件扩展名”。如果是,请确保列表中有 .svc 条目。否则 IIS 将阻止提供该文件。