.net - webHttpBinding WCF 服务通过 HTTP 响应,但不通过 HTTPS 响应

标签 .net wcf rest https webhttpbinding

我正在我的计算机上开发 WCF Restfull 服务,当我访问 HTTP 服务端点时,服务按预期响应。但是,当我访问 HTTPS 端点时,我收到 404 Not Found 回复。

Https 调用不会触发已实现为 serviceAuthorizationManagerTypeCustomAuthorizationManager

知道为什么这不起作用吗?为什么基地址是 HTTPS 时却允许 HTTP 流量?

HTTP 响应 enter image description here

HTTPS 响应

enter image description here

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" 并且它按预期工作。

详情可见this MSDN article

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/

相关文章:

c# - 缺少系统.Windows

c# - 不能发送任何非通用类型的东西

c# - 如何简化 Silverlight 4 中的 WCF 调用

http - 以 RESTful 方式递增资源计数器 : PUT vs POST

api - 如何构建 REST API XML 响应

c# - 在网站上公开一些实时数据 - ASP.NET 的新手,需要指南

c# - 在现有数据表中添加具有顺序编号的新列的最佳方法

wcf - 通过 VBScript 调用 WCF 服务

java - Spring Boot Bean 验证@NotEmpy 不起作用

c# - 当我在程序启动后复制 DLL 时,运行时加载程序集失败