[英]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.