如何在WCF服务中启用HTTPS

时间:2014-11-06 16:43:26

标签: wcf https wcf-security basichttpbinding wcf-configuration

我已在IIS上托管我的服务。

托管服务已应用SSL证书,在浏览URL时,它显示为HTTPS。

但是,当我将此URL用于客户端应用程序(ASP.NET WEB应用程序)时,它允许添加https//domain/service.svc但是,在客户端配置中,它显示为http而不是https。当手动更改时,它会给出如下错误:The provided URI scheme 'https' is invalid; expected 'http'.

以下是WCF服务配置(在IIS上托管):

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="customBehavior">
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <basicHttpBinding>
    <binding name="basicBindingConfiguration" closeTimeout="00:05:00"
            openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />

      <security mode="None">

      </security>
    </binding>
  </basicHttpBinding>
</bindings>

<serviceHostingEnvironment  multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
<services>
  <service name="Administrator.OAP.CRMServices.CRMServices"
           behaviorConfiguration="customBehavior">
    <endpoint address=""
              binding="basicHttpBinding"
              bindingConfiguration="basicBindingConfiguration"
              contract="Administrator.OAP.CRMServices.Contracts.ICRMServices" />
  </service>
</services>

任何人都可以指导我这里有什么问题或需要更改以仅使用HTTPS来使用此服务吗?

1 个答案:

答案 0 :(得分:6)

你的绑定有这个:

<security mode="None">

这意味着您的服务不会期望使用任何类型的安全性。 HTTPS是传输身份验证,因此您需要设置:

<security mode="Transport">

以下链接包含有关在WCF中设置传输安全性的有用信息:http://msdn.microsoft.com/en-us/library/ms733043(v=vs.110).aspx