WCF Over HTTPS(消息和传输)404 错误(找不到页面)

WCF Over HTTPS (Message & Transport) 404 Error (Page Not Found)

我的 WCF 服务与身份验证和消息安全类型配合得很好。

但是我需要通过 https 与 WCF 通信(它必须在 url 中),所以我需要添加传输安全类型。

(我使用的是自签名证书)

这是我的绑定配置:

 <bindings>
  <wsHttpBinding>
    <binding name="Binding">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

这是我的服务配置:

  <services>
  <service name="WcfService1.Service1" behaviorConfiguration="MyServiceTypeBehaviors">
    <host>
      <baseAddresses>
        <add baseAddress="https://localhost/Service1.svc"/>
      </baseAddresses>
    </host>
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding" contract="WcfService1.IService1" />
  </service>
</services>

这是我的行为配置:

  <behavior name="MyServiceTypeBehaviors" >

      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"  />
      <serviceDebug includeExceptionDetailInFaults="false" />

      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WcfService1.UserValidate,WcfService1"/>
        <serviceCertificate findValue="localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
      </serviceCredentials>
    </behavior>

但就像真正的 WCF 服务一样,一切都不会一帆风顺:

Could not find a base address that matches scheme https for the endpoint with binding WSHttpBinding. Registered base address schemes are [http].

This webpage is not available

这是我的全部 Web.Config :

  <?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>

    <services>
      <service name="WcfService1.Service1" behaviorConfiguration="MyServiceTypeBehaviors">
        <host>
          <baseAddresses>
            <add baseAddress="https://localhost/Service1.svc"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding" contract="WcfService1.IService1" />
      </service>
    </services>

    <bindings>
      <wsHttpBinding>
        <binding name="Binding">
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>

           <!--My Custom Behavior-->
        <behavior name="MyServiceTypeBehaviors" >

          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"  />
          <serviceDebug includeExceptionDetailInFaults="false" />

          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WcfService1.UserValidate,WcfService1"/>
            <serviceCertificate findValue="localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
          </serviceCredentials>
        </behavior>

      </serviceBehaviors>
    </behaviors>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

提前致谢。

更新

我已将 IIS 应用程序设置为绑定到 Https(感谢 Daniel Holmkviste)。

现在我得到 404(未找到)的基地址。 ("https://localhost/Service1.svc")

但好消息是我有一个绿色锁,当我按下它时,我看到 "LocalHost" 已验证身份。

但是为什么现在找不到页面了?

Http(从VS执行wcf时自动URL地址)“http://localhost:22535/Service1.svc”仍然报错:

Could not find a base address that matches scheme https for the endpoint with binding WSHttpBinding. Registered base address schemes are [http].

指定元数据。

<endpoint address="mex" binding="mexHttpsBinding" contract="IMetaDataExchange"/>

要在 VS 中启用 https,您必须将项目的属性配置为使用 IIS。

终于!答案是 打开 HTTP 激活。

在 windows 中搜索 "Turn Windows Features on or off"。

打开.NET Framework 4.5 Advanced Services

打开WCF Services

勾选HTTP Activation