katit
katit

Reputation: 17895

Configure SSL binding for RESTful WCF. How?

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

Upvotes: 4

Views: 6506

Answers (3)

sky
sky

Reputation: 441

The accepted answer did not work for me because I needed to keep my standard endpoints element. I was able to remove my http-binding and only leave the https-binding in IIS by adding a <webHttpBinding> section to my Web.config

Make sure to not set the name property on the <binding>, otherwise this will not work

Relevant part of my Web.config:

 <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <bindings>
      <webHttpBinding>
        <binding>
          <!-- Comment out the following line if HTTP is used. If HTTPS is used, leave it enabled -->
          <security mode="Transport"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="false" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

Upvotes: 1

Hupperware
Hupperware

Reputation: 979

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>

Upvotes: 3

Dreamwalker
Dreamwalker

Reputation: 3035

Try this

<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>
    <security mode="Transport" />
  </webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>

Upvotes: -1

Related Questions