Crash in HttpMessageEncodingBindingElement.BuildChannelListener()

Topics: Web Api
May 4, 2011 at 10:09 AM
Edited May 4, 2011 at 10:11 AM

Here's the relevant stack trace:

System.ArgumentException was unhandled by user code
  Message=The provided URI scheme 'https' is invalid; expected 'http'.
Parameter name: context.ListenUriBaseAddress
       at System.ServiceModel.Channels.TransportChannelListener..ctor(TransportBindingElement bindingElement, BindingContext context, MessageEncoderFactory defaultMessageEncoderFactory, HostNameComparisonMode 

       at System.ServiceModel.Channels.HttpChannelListener..ctor(HttpTransportBindingElement bindingElement, BindingContext context)
       at System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener[TChannel](BindingContext context)
       at System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[TChannel]()
       at Microsoft.ApplicationServer.Http.Channels.HttpMessageEncodingBindingElement.BuildChannelListener[TChannel](BindingContext context) in D:\DevData\VSToolkits\WCFWeb\wcf\WCFWebApi\Http\Src

\Microsoft.ApplicationServer.Http\Microsoft\ApplicationServer\Http\Channels\HttpMessageEncodingBindingElement.cs:line 117
       at System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[TChannel]()

This happens when running the web service under IIS 7.5. I've tested with both the VS Development Server and IIS Express as well, and neither of these other web servers causes this problem.

I set a break point in HttpConfigurableServiceHostFactory.CreateServiceHost():

        protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            var host = new HttpConfigurableServiceHost(serviceType, this.Builder, baseAddresses);
            return host;

I noticed that the baseAddresses array has 2 elements when running under IIS 7.5. The first is an http URI, and the second one is an https URI.

When running under VS Development Server or IIS Express, the baseAddresses array has only one element containing an http URI.

Interestingly, when setting up the route with the old method:

RouteTable.Routes.Add(new ServiceRoute("api/route", new WebServiceHostFactory3(), typeof(ContactsResource)));

there is no crash.

May 4, 2011 at 10:18 AM

One workaround (but not an ideal one) is to remove the https binding for my root web site in IIS 7.5.