简体   繁体   中英

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

I've WCF service that is working great with authentication and Message Security Type.

But I need to communicate with the WCF over https (its have to be in the url), so I need to add Transport Security Type.

(I'm using self sign certificate)

This is my binding config:

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

This is my Services config :

  <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>

This is my Behavior config:

  <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>

But like a true WCF Service nothing goes smooth:

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

This is my entire 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>

Thanks in advance.

Update

I've set the IIS application to bind on Https (Thanks Daniel Holmkviste).

Now I get 404 (not found) for the base address. (" https://localhost/Service1.svc ")

But the good news I have a green lock and when I press it i see "LocalHost" with identity verified.

But why now it cant find the page ?

The Http (the automatically URL address when execute the wcf from the VS) " http://localhost:22535/Service1.svc " still give this error :

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

Specify the metadata.

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

To enable https in VS you have to configure the properties of your project to use IIS.

Finally! the answer is to turn the HTTP Activation On.

Search "Turn Windows Features on or off" in windows.

Open .NET Framework 4.5 Advanced Services

Open WCF Services

Check HTTP Activation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM