C# – Configure SSL binding for RESTful WCF. How

cnetrestwcfweb.config

My current config looks like so:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <!--Set limit to 5 megabytes-->
        <standardEndpoint helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="5242880">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647" />

        </standardEndpoint>

      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

This works when I have http and https bindings both configured for my website.

I connect to service via https and everything works great.

Now I want to remove http binding on IIS completely. And I started to get error like this:

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

[InvalidOperationException: Could not find a base address that matches
scheme http for the endpoint with binding WebHttpBinding. Registered
base address schemes are [https].]
System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri
relativeOrAbsoluteUri, Binding binding, UriSchemeKeyedCollection
baseAddresses) +16582113
System.ServiceModel.Description.ConfigLoader.ConfigureEndpointAddress(ServiceEndpointElement
serviceEndpointElement, ServiceHostBase host, ServiceEndpoint
endpoint) +117
System.ServiceModel.Description.ConfigLoader.ConfigureEndpoint(StandardEndpointElement
standardEndpointElement, ServiceEndpointElement
serviceEndpointElement, ContextInformation context, ServiceHostBase
host, ServiceDescription description, ServiceEndpoint& endpoint,
Boolean omitSettingEndpointAddress) +937
System.ServiceModel.Description.ConfigLoader.LookupEndpoint(ServiceEndpointElement
serviceEndpointElement, ContextInformation context, ServiceHostBase
host, ServiceDescription description, Boolean
omitSettingEndpointAddress) +8728167
System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost
host, IDictionary`2 implementedContracts, String
multipleContractsErrorMessage, String standardEndpointKind) +982
System.ServiceModel.Web.WebServiceHost.OnOpening() +311
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan
timeout) +612
System.ServiceModel.HostingManager.ActivateService(String
normalizedVirtualPath) +255
System.ServiceModel.HostingManager.EnsureServiceAvailable(String
normalizedVirtualPath) +1172

[ServiceActivationException: The service '/DEMO/mobile' cannot be
activated due to an exception during compilation. The exception
message is: Could not find a base address that matches scheme http for
the endpoint with binding WebHttpBinding. Registered base address
schemes are [https]..] System.Runtime.AsyncResult.End(IAsyncResult
result) +901424
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult
result) +178702
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult
ar) +136

I found bunch of samples for WCF but REST WCF looks different on config side and I want to understand why it compains. From looks of my config – it should not work over SSL at all but it does work when https binding present..

Best Answer

Do what the error says... fix your binding

 <services>
      <service name="service" behaviorConfiguration="serviceBehavior">
        <endpoint address="" binding="webHttpBinding"
              bindingConfiguration="https"
contract="IContract" behaviorConfiguration="endpointBehavior">
        </endpoint>
      </service>
    </services> 

<bindings>
 <webHttpBinding>
  <binding name="https" maxReceivedMessageSize="65536">
    <security mode="Transport" />
    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647" />

  </binding>
 </webHttpBinding>
</bindings>