REST WCF Service Over SSL

2019-03-21 03:45发布

I am trying to configure a REST WCF service over SSL and I keep getting:

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

Can somebody please take a look at my config file? Thanks.

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBinding1">
          <security>
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
       <mexHttpsBinding>
         <binding name="mexHttpsBinding1"/>
      </mexHttpsBinding>
      <webHttpBinding>
        <binding name="webHttpBinding1">
          <security mode="Transport" />
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="serviceBehavior" name="CompanyX.WebServices.WebApi">
        <endpoint address="" behaviorConfiguration="WebApiBehavior" binding="webHttpBinding"
          bindingConfiguration="webHttpBinding1" contract="CompanyX.WebServices.IWebApi">
          <identity>
           <certificateReference x509FindType="FindBySubjectName" findValue="CompanyXDev"
              isChainIncluded="false" storeName="My" storeLocation="LocalMachine" />
          </identity>
        </endpoint>
        <endpoint binding="mexHttpsBinding" bindingConfiguration="mexHttpsBinding1"
          name="mex" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebApiBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <serviceMetadata httpsGetEnabled="true" httpGetBinding="" httpsGetBinding="webHttpBinding"
            httpsGetBindingConfiguration="webHttpBinding1" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <clientCertificate>
              <certificate findValue="CompanyXDev" x509FindType="FindBySubjectName" />
            </clientCertificate>
            <serviceCertificate findValue="CompanyXDev" x509FindType="FindBySubjectName" />
            <userNameAuthentication userNamePasswordValidationMode="Custom"
              customUserNamePasswordValidatorType="CompanyX.WebServices.CredentialsValidator, CompanyX.WebServices" />
            <peer>
              <certificate findValue="CompanyXDev" storeLocation="LocalMachine"
                x509FindType="FindBySubjectName" storeName="My" />
            </peer>
            <issuedTokenAuthentication>
              <knownCertificates>
                <add findValue="CompanyXDev" storeLocation="LocalMachine" storeName="My"
                  x509FindType="FindBySubjectName" />
              </knownCertificates>
            </issuedTokenAuthentication>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

标签: wcf rest ssl
3条回答
劫难
2楼-- · 2019-03-21 04:37

You need to add a https binding in IIS.

  1. Navigate to your site in IIS
  2. Click 'Bindings...' in the Actions panel on the right.
  3. Click 'Add'
  4. Select 'https' and select a certificate.
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-03-21 04:43

Let me guess: You are running your service from Visual Studio in Developement web server (Cassini), don't you? Development web server does not support HTTPS. You have to host your service in IIS and follow Greg's advice to add HTTPS binding for the site.

查看更多
萌系小妹纸
4楼-- · 2019-03-21 04:47

Two choices:

  1. Specify the full address in the endpoints.

  2. Specify somewhere in the tag the base addresses used for the host, for example:

<host>
  <baseAddresses>
    <add baseAddress="http://localhost:8000/service"/>
    <add baseAddress="https://localhost:8001/service"/>
  </baseAddresses>
</host>
查看更多
登录 后发表回答