[wcf] How to fix "could not find a base address that matches schema http"... in WCF

I'm trying to deploy a WCF service to my server, hosted in IIS. Naturally it works on my machine :)

But when I deploy it, I get the following error:

This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.

Googling on this, I find that I have to put a serviceHostingEnvironment element into the web.config file:

<serviceHostingEnvironment>
  <baseAddressPrefixFilters>
    <add prefix="http://mywebsiteurl"/>
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>

But once I have done this, I get the following:

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

It seems it doesn't know what the base address is, but how do I specify it? Here's the relevant section of my web.config file:

<system.serviceModel>
  <serviceHostingEnvironment>
    <baseAddressPrefixFilters>
      <add prefix="http://mywebsiteurl"/>
    </baseAddressPrefixFilters>
  </serviceHostingEnvironment>

  <behaviors>
    <serviceBehaviors>
      <behavior name="WcfPortalBehavior">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IWcfPortal"
               maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
               receiveTimeout="00:10:00" sendTimeout="00:10:00"
               openTimeout="00:10:00" closeTimeout="00:10:00">
        <readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647"
               maxStringContentLength="2147483647"/>
      </binding>
    </basicHttpBinding>
  </bindings>

  <services>
    <service behaviorConfiguration="WcfPortalBehavior" name="Csla.Server.Hosts.Silverlight.WcfPortal">
      <endpoint address="" binding="basicHttpBinding" contract="Csla.Server.Hosts.Silverlight.IWcfPortal"
      bindingConfiguration="BasicHttpBinding_IWcfPortal">
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
  </services>
</system.serviceModel>

Can anybody shed some light on what's going on and how to fix it?

This question is related to wcf iis basichttpbinding

The answer is


The solution is to define a custom binding inside your Web.Config file and set the security mode to "Transport". Then you just need to use the bindingConfiguration property inside your endpoint definition to point to your custom binding.

See here: Scott's Blog: WCF Bindings Needed For HTTPS


Confirmed my fix:

In your web.config file you should configure it to look as such:

<system.serviceModel >
    <serviceHostingEnvironment configSource=".\Configurations\ServiceHosting.config" />
    ...

Then, build a folder structure that looks like this:

/web.config
/Configurations/ServiceHosting.config
/Configurations/Deploy/ServiceHosting.config

The base serviceHosting.config should look like this:

<?xml version="1.0"?>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
    <baseAddressPrefixFilters>
    </baseAddressPrefixFilters>
</serviceHostingEnvironment>

while the one in /Deploy looks like this:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
    <baseAddressPrefixFilters>
        <add prefix="http://myappname.web707.discountasp.net"/>
    </baseAddressPrefixFilters>
</serviceHostingEnvironment>

Beyond this, you need to add a manual or automated deployment step to copy the file from /Deploy overtop the one in /Configurations. This works incredibly well for service address and connection strings, and saves effort doing other workarounds.

If you don't like this approach (which scales well to farms, but is weaker on single machine), you might consider adding a web.config file a level up from the service deployment on the host's machine and put the serviceHostingEnvironment node there. It should cascade for you.


Any chance your IIS is configured to require SSL on connections to your site/application?


There should be a way to solve this pretty easily with external config sections and an extra deployment step that drops a deployment specific external .config file into a known location. We typically use this solution to handle the different server configurations for our different deployment environments (Staging, QA, production, etc) with our "dev box" being the default if no special copy occurs.


I had to do two things to the IIS configuration of the site/application. My issue had to do with getting net.tcp working in an IIS Web Site App:

First:

  1. Right click on the IIS App name.
  2. Manage Web Site
  3. Advanced Settings
  4. Set Enabled protocols to be "http,net.tcp"

Second:

  1. Under the Actions menu on the right side of the Manager, click Bindings...
  2. Click Add
  3. Change type to "net.tcp"
  4. Set binding information to {open port number}:*
  5. OK

Try changing the security mode from "Transport" to "None".

      <!-- Transport security mode requires IIS to have a
           certificate configured for SSL. See readme for
           more information on how to set this up. -->
      <security mode="None">

If it is hosted in IIS, there is no need to specify a base address, it will be the address of the virtual directory.


If you want to use baseAddressPrefixFilters in web.config, you must setup IIS (6) too. This helped me:

1/ In IIS find your site. 2/ Properties / Web site (tab) / IP address -> Advanced button 3/ Add new host header on the same port which you will use in web.config.


Only the first base address in the list will be taken over (coming from IIS). You can't have multiple base addresses per scheme prior to .NET4.


Examples related to wcf

Create a asmx web service in C# using visual studio 2013 WCF Exception: Could not find a base address that matches scheme http for the endpoint WCF Service, the type provided as the service attribute values…could not be found WCF error - There was no endpoint listening at How can I pass a username/password in the header to a SOAP WCF Service The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'NTLM' Content Type application/soap+xml; charset=utf-8 was not supported by service The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8) maxReceivedMessageSize and maxBufferSize in app.config how to generate a unique token which expires after 24 hours?

Examples related to iis

ASP.NET Core 1.0 on IIS error 502.5 CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default Publish to IIS, setting Environment Variable IIS Manager in Windows 10 The page cannot be displayed because an internal server error has occurred on server The service cannot accept control messages at this time NuGet: 'X' already has a dependency defined for 'Y' Changing project port number in Visual Studio 2013 System.Data.SqlClient.SqlException: Login failed for user "This operation requires IIS integrated pipeline mode."

Examples related to basichttpbinding

The maximum message size quota for incoming messages (65536) has been exceeded BasicHttpBinding vs WsHttpBinding vs WebHttpBinding How to fix "could not find a base address that matches schema http"... in WCF