[英]webHttpBinding WCF service responds over HTTP but not HTTPS
我正在计算机上开发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>
合同
[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;
}
}
好的,问题出在绑定上。
security mode="TransportCredentialOnly"
,它不提供完全传输(HTTPS)安全性。
我将值更改回security mode="Transport"
,并且按预期工作。
可以在此MSDN文章中找到详细信息
无-表示HTTP请求不使用安全性。
传输-表示HTTP请求使用了传输级安全性。
TransportCredentialOnly-指示仅提供基于HTTP的客户端身份验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.