WCF 2009年9月13日 0 错误:此集合已经包含方案 http 的地址。此集合中每个方案中最多只能包含一个地址。(This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.)
原因:此 WCF 宿主是 IIS ,并且此站点配置了多个主机头,如果 www.example.com 与 www.example-alias.com 。但 WCF 不支持对 IIS (Http Binding) 中的 WCF 多个主机头绑定。
解决:
方法1. 用绑定不同主机头的多个网站来部署这个 WCF。
方法2. 自定义 ServiceHostFactory
详细讨 论:
There can be at most one address per scheme in this collection.
How can WCF support multiple IIS Binding specified per site ?
WCF: Hosting multiple WCF services as one single service
转贴网上的解决方案2:http://blog.befruit.com/2008/09/wcf-error-this-collection-already.html 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.