出错信息:
“/”应用程序中的服务器错误。
——————————————————————————–
此集合已经包含方案 http 的地址。此集合中每个方案中最多只能包含一个地址。
参数名: item
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentException: 此集合已经包含方案 http 的地址。此集合中每个方案中最多只能包含一个地址。
参数名: item
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[ArgumentException: 此集合已经包含方案 http 的地址。此集合中每个方案中最多只能包含一个地址。
参数名: item]
System.ServiceModel.UriSchemeKeyedCollection.InsertItem(Int32 index, Uri item) +11520590
System.Collections.Generic.SynchronizedCollection`1.Add(T item) +67
System.ServiceModel.UriSchemeKeyedCollection..ctor(Uri[] addresses) +49
System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +129
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +28
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +331
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +11659932
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +42
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479
[ServiceActivationException: 由 于编译过程中出现异常,无法激活服务“/TcProcess.Host/ArticleService.svc”。异常消息为: 此集合已经包含方 案 http 的地址。此集合中每个方案中最多只能包含一个地址。
参数名: item。]
System.ServiceModel.AsyncResult.End(IAsyncResult result) +11531006
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +278
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.3082; ASP.NET 版本:2.0.50727.3082
Multi-named web sites and WCF
Glav posts about a problem I’ve also had recently – that Matt helped me figure out how to solve.
The exception is (repeated here for seach purposes):
This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
解决办法:
The way to solve this problem is to setup multiple web sites in IIS (rather than having one site that has multiple Host entries) – and point all the websites to the same directory.
The Problem:
I recently ran into this problem issue trying to host a service through my shared web hosting service provider.
Server Error in ‘/’ Application.
——————————————————————————–
This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
The Solution:
The solution, since WCF services hosted in IIS can have only one Base Address was to create a custom service factory to intercept and remove the additional unwanted base addresses that IIS was providing. In my case IIS was providing:
domain.com
www.domain.com
dedicatedserver1234.hostingcompany.com
We are able to customize our .svc file to specif a custom serive factory
We are then able to create our custom factory by inheriting from ServiceHostFactory and overriding as required
class CustomHostFactory : ServiceHostFactory { protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { CustomHost customServiceHost = new CustomHost(serviceType, baseAddresses[1]); return customServiceHost; } } class CustomHost : ServiceHost { public CustomHost(Type serviceType, params Uri[] baseAddresses) : base(serviceType, baseAddresses) { } protected override void ApplyConfiguration() { base.ApplyConfiguration(); } }
In my case I decided to pass through baseAddresses[1] (which was the www. address) but it would probably be wise to specify that address you want to prevent changes by your web host from impacting yoru code.
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.