WCF error: "This collection already contains an address with scheme http"
I met this error, and wondered what this could be. The explanation is that "WCF services hosted in IIS can have only one Base Address", meaning that in IIS the website hosting the service can not be associated to http://www.example.com and http://example.com at the same time.
I don't know why this prevents a service to work, but I know this is annoying.
I found a couple of bloggers like Rob suggesting a solution with a coded custom ServiceHostFactory, which sounds terribly complicated to me as a workaround.
Fortunately there is a much simpler solution, just by touching the web.config file. Just add the following lines in the system.serviceModel section:
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://www.example.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
to only keep the service address.
I don't know why this prevents a service to work, but I know this is annoying.
I found a couple of bloggers like Rob suggesting a solution with a coded custom ServiceHostFactory, which sounds terribly complicated to me as a workaround.
Fortunately there is a much simpler solution, just by touching the web.config file. Just add the following lines in the system.serviceModel section:
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://www.example.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
to only keep the service address.
Labels: WCF

17 Comments:
You Rock! But I wonder why nobody is commenting for an elegant solution.
By
Anonymous, At
September 10, 2008 4:40 PM
Thanks, works like charm!
By
Anonymous, At
September 25, 2008 7:18 AM
Have you ever run in to an instance where even adding those lines to the config still gives you that error? Thats what is happening to me.
By
Anonymous, At
October 21, 2008 6:08 PM
Thank you for saving me so much time, worked perfectly!
By
Robert, At
November 17, 2008 9:33 AM
Excellent!
Thanks
By
Levi, At
December 4, 2008 3:18 AM
Thanks for posting that simple approach.
By
Jonathan, At
January 21, 2009 12:17 AM
Cool, works here too!
By
Anonymous, At
April 18, 2009 1:03 AM
Wow! Wish all the MS articles & books on this subject mentioned this. But I'm glad you did. Thanks!
I couldn't get it to work for localhost, but I'm good with my machine name.
By
Anonymous, At
May 20, 2009 7:55 PM
Very, very nice!
By
Anonymous, At
June 28, 2009 10:16 PM
This didn't work for me either. Downer :(
By
Anonymous, At
August 17, 2009 4:02 AM
Perfect!!!. Smart and simple. Thanks
By
yavas, At
August 22, 2009 9:25 PM
Thanks for that solution. I works perfect and was exactly what I needed!!!
By
Anonymous, At
August 27, 2009 4:27 PM
Thank you!
By
Anonymous, At
September 16, 2009 10:41 PM
Thanx a lot!!!!!!!
U saved from coding serviceHostFactory.
Real too good.........
By
Ritu Mangla, At
September 25, 2009 4:19 PM
Brilliantly simple. Thank you.
By
Erik Madsen, At
October 2, 2009 11:26 PM
Splendid, Thank you!
By
Alexander, At
October 23, 2009 6:39 PM
Can’t believe it’s so simple to fix the problem. But don’t get why it can be a fix.
By
Anonymous, At
March 30, 2010 9:16 PM
Post a Comment
<$I18N$LinksToThisPost>:
Create a Link
<< Home