Search code examples
xmlwcfweb-configwcf-endpoint

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


i went through some previous questions, but i think am missing somewhere, As WCF is totally new for me.

web.config in WCF service application

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

In MVC application, other application am consuming above code service.

added service reference with default settings and automatically generated endpoint address with http, if i change it to https it's breaking with error.


Solution

  • In WCF, we should configure an extra service endpoint for HTTPS protocol, which requires the transport layer security mode.

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

    The below configuration supports both HTTP protocol and HTTPS protocol.

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

    We could also use ProtocolMapping section to simplify the configuration. The below configuration support both HTTP and HTTPS protocol.

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

    Official document.
    https://learn.microsoft.com/en-us/dotnet/framework/wcf/simplified-configuration
    Feel free to let me know if there is anything I can help with.