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

时间:2015-05-13 12:55:27

标签: c# web-services wcf

我的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服务一样顺利:

  

无法找到与绑定WSHttpBinding的端点的方案https匹配的基址。注册的基地址方案是[http]。

  

此网页不可用

这是我的整个网站.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(未找到)基地址。 (&#34; https://localhost/Service1.svc&#34)

但好消息我有绿锁,当我按下它时,我看到&#34; LocalHost&#34;身份验证。

但为什么现在找不到这个页面?

Http(从VS执行wcf时的自动URL地址)&#34; http://localhost:22535/Service1.svc&#34;仍然给出这个错误:

  

无法找到与绑定WSHttpBinding的端点的方案https匹配的基址。注册的基地址方案是[http]。

2 个答案:

答案 0 :(得分:0)

指定元数据。

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

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

答案 1 :(得分:0)

最后!答案是打开HTTP激活。

搜索&#34;打开或关闭Windows功能&#34;在Windows中。

打开.NET Framework 4.5 Advanced Services

打开WCF Services

检查HTTP Activation