我正在我的计算机上开发 WCF Restfull 服务,当我访问 HTTP 服务端点时,服务按预期响应。但是,当我访问 HTTPS 端点时,我收到 404 Not Found 回复。
Https 调用不会触发已实现为 serviceAuthorizationManagerType
的 CustomAuthorizationManager
知道为什么这不起作用吗?为什么基地址是 HTTPS 时却允许 HTTP 流量?
HTTP 响应
HTTPS 响应
Web.config
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="TransportCredentialOnly">
<!--Basic authentication is NOT supported when running webHttpBinding through IIS
see - http://blogs.msdn.com/b/phenning/archive/2008/01/11/custom-usernamepassword-validators-in-net-framework-3-5.aspx
and a resolution - http://allen-conway-dotnet.blogspot.co.uk/2012/07/using-basic-authentication-in-rest.html-->
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="restfulBehavior" name="Chubb.SurveyRecommendations.Service.SurveyRecommendationsService">
<!--webHttpBinding allows exposing service methods in a RESTful manner-->
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpTransportSecurity" behaviorConfiguration="webHttpBehavior" contract="Chubb.SurveyRecommendations.Service.ISurveyRecommendations"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="https://localhost:44300/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="restfulBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceAuthorization serviceAuthorizationManagerType="Chubb.SurveyRecommendations.Service.Security.CustomAuthorizationManager, Chubb.SurveyRecommendations.Service"/>
</behavior>
</serviceBehaviors>
<!--Required default endpoint behavior when using webHttpBinding-->
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
契约(Contract)
[OperationContract]
[WebGet(UriTemplate = "Echo/{value}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]
string Echo(string value);
服务
public class SurveyRecommendationsService : ISurveyRecommendations
{
public string Echo(string value)
{
if (string.IsNullOrWhiteSpace(value))
return string.Empty;
return value;
}
}
最佳答案
好的,问题出在绑定(bind)上。
指定的security mode="TransportCredentialOnly"
不提供完全传输 (HTTPS) 安全性。
我将值更改回 security mode="Transport"
并且它按预期工作。
None - Indicates no security is used with HTTP requests.
Transport - Indicates that transport-level security is used with HTTP requests.
TransportCredentialOnly - Indicates that only HTTP-based client authentication is provided.
关于.net - webHttpBinding WCF 服务通过 HTTP 响应,但不通过 HTTPS 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24241655/