提供的 URI 方案 'http' 无效;预计 'https'。参数名称

The provided URI scheme 'http' is invalid; expected 'https'. Parameter name

我回答了之前的一些问题,但我认为我遗漏了某个地方,因为 WCF 对我来说是全新的。

web.config 在 WCF 服务应用程序中

  <service behaviorConfiguration="BehaviourName" name="ProjectName.ServiceName">
    <endpoint address="" binding="basicHttpBinding" contract="ProjectName.IServiceName">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <add baseAddress="https://aaa.bbbbbb.com/IISDeployedFolderName"/>
      </baseAddresses>
    </host>
  </service>
  ....................
  .....................

  <behavior name="BehaviourName">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="false" />
  </behavior>
  ............................
  ..........................
  <basicHttpBinding>
    <binding name="secureHttpBinding">
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="Certificate" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
  ..........................
  .........................
  <protocolMapping>
    <add binding="basicHttpBinding" scheme="https" />
  </protocolMapping>
  ............................
  ..............................

在 MVC 应用程序中,其他应用程序正在使用上述代码服务。

添加了具有默认设置的服务引用和使用 http 自动生成的端点地址,如果我将其更改为 https,它会因错误而中断。

在 WCF 中,我们应该为 HTTPS 协议配置一个额外的服务端点,这需要传输层安全模式。

    <services>
      <service name="WcfService1.Service1">
        <!--please pay attention to that apply the binding configuration by means of bindingConfiguration property.-->
        <endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" bindingConfiguration="mybinding"></endpoint>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"></endpoint>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="mybinding">
          <security mode ="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </basicHttpBinding>
</bindings>

以下配置同时支持HTTP协议和HTTPS协议。

  <system.serviceModel>
    <services>
      <service name="WcfService1.Service1">
        <!--please pay attention to that apply the binding configuration by means of bindingConfiguration property.-->
        <endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" bindingConfiguration="mybinding"></endpoint>
        <endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="mybinding">
          <security mode ="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

我们也可以使用 ProtocolMapping 部分来简化配置。以下配置同时支持 HTTP 和 HTTPS 协议。

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <protocolMapping>
      <add binding="basicHttpBinding" scheme="http"/>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
  </system.serviceModel>

官方文档。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/simplified-configuration
如果有什么我可以帮忙的,请随时告诉我。