There can be at most one address per scheme in this collection.
-
2007年2月8日 21:45
When hosting my .svc in IIS, 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.
I know this is caused by sites that have multiple bindings. In my case, I am a web hoster and have sites with multiple host headers per site.
Is there any way to override this behavior in web.config? I've tried the following with no effect:
<host>
<baseAddresses>
<clear/>
<add baseAddress="http://mydomain.com" />
</baseAddresses>
</host>Any ideas for how to make this work without forcing my customers to modify their source?
Thanks,
Mark
答案
-
2007年2月22日 17:06
Hi Mark,
Unfortunately the behavior is by design. WCF does not support multiple IIS bindings for the same protocol (here it is HTTP) for the same web site. This is for simplicity, especially it did not seem to be an important scenario. Is this a very important scenario for you? Can't you host different services in different web sites (with different ports of course)? If this does block you, we may think about revisiting this issue again.
Thanks,
Wenlong
全部回复
-
2007年2月14日 4:44
Hi, Mark:
Are you using reliable messaging? You might be hitting this bug:
http://blogs.msdn.com/drnick/archive/2006/12/05/incompatible-addressing-with-reliable-messaging.aspx.
The workaround is that if you need to have multiple service endpoints that both use reliable messaging but have different message addressing versions, then you should create a new application domain to keep the endpoints separate.
Hope this helps.
-
2007年2月22日 14:36
I got the same problem. Could you please tell me where shall I put the <host> section ? I tried the following, this is the only place I don't get compile error. However, the program can not recognize the second and third services.
<system.serviceModel>
<services><service name="OpusEdge.TestModel.Service1" behaviorConfiguration="returnFaults">
<host>
<baseAddresses>
<add baseAddress="http://localhost:2111/WCFService" />
</baseAddresses>
</host><endpoint contract="OpusEdge.TestModel.IService1" binding="wsHttpBinding"/>
</service>
<service name="OpusEdge.TestModel.Service2" behaviorConfiguration="returnFaults">
<endpoint contract="OpusEdge.TestModel.IService2" binding="wsHttpBinding"/>
</service>
<service name="OpusEdge.TestModel.Service3" behaviorConfiguration="returnFaults">
<endpoint contract="OpusEdge.TestModel.IService3" binding="wsHttpBinding"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="returnFaults" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>Thanks,
Bing
Mark A. Richman wrote: When hosting my .svc in IIS, 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.
I know this is caused by sites that have multiple bindings. In my case, I am a web hoster and have sites with multiple host headers per site.
Is there any way to override this behavior in web.config? I've tried the following with no effect:
<host>
<baseAddresses>
<clear/>
<add baseAddress="http://mydomain.com" />
</baseAddresses>
</host>Any ideas for how to make this work without forcing my customers to modify their source?
Thanks,
Mark -
2007年2月22日 17:06
Hi Mark,
Unfortunately the behavior is by design. WCF does not support multiple IIS bindings for the same protocol (here it is HTTP) for the same web site. This is for simplicity, especially it did not seem to be an important scenario. Is this a very important scenario for you? Can't you host different services in different web sites (with different ports of course)? If this does block you, we may think about revisiting this issue again.
Thanks,
Wenlong
-
2007年2月23日 16:27
Wenlong Dong wrote: Hi Mark,
Unfortunately the behavior is by design. WCF does not support multiple IIS bindings for the same protocol (here it is HTTP) for the same web site. This is for simplicity, especially it did not seem to be an important scenario. Is this a very important scenario for you? Can't you host different services in different web sites (with different ports of course)? If this does block you, we may think about revisiting this issue again.
Thanks,
Wenlong
I don't have multiple bindings but I am getting this same error. Let me explain. When I copy the assemblies and the .svc to the remote machine I get an error that Microsoft.CommerceServer.Internal.ContentListHelper.dll could not be loaded (I am developing on a 32 bit OS and copying to a 64 bit OS). Looking on the remote computer I find another assembly with the same name and replaced it. The new files size was 91KB and the old one was 71KB. I am assuming that the difference in size is because of the 64 bit OS. With the newly copied file I get the error that is described in this thread. Is this related to the 64 bit OS or is there another problem?
Thank you.
Kevin
-
2007年2月28日 3:15This is quite important, since I'm a web hoster. Each of my customers' sites are provisioned with serveral ServerBindings in the metabase, not just www.domain.com. This is causing the problem, espcially for shared hosting.
I'd like to offer my customers a simple workaround via web.config if possible. Not everyone has the skills or desire to modify their WCF service just to work around this "feature". They'll just go to another web host that doesn't allow multiple host headers. Not good for business.
Can you offer a workaround, or point me to a KB article that I can give my customers who want to use WCF?
Thanks,
Mark -
2007年6月8日 23:23I also have this problem with multiple headers to a website and consider it an important feature to have this ability.
-
2007年6月9日 0:05
You might be able to work around this with a custom ServiceHostFactory, whose CreateServiceHost method looks through the Uri[] that IIS passes it, and filters out the extras so that only one Uri (the host header appropriate to the WCF service) is used. A trivial subclass that just overrides this one method and filters the Uri[] parameter and then calls into the base class might be sufficient.
-
2007年11月9日 18:05
I tried this custom ServiceHostFactory suggestion, but then I get the error (my binding requires https):
Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http].
If I try setting to the https Uri, I get an error because the MexdataExchange needs http. How do I work round this?
Thanks in advance
-
2007年11月12日 14:35
Maybe if I re-phrase this, someone might know of a solution:
How can I use ServiceHostFactory in an IIS-hosted app to work with my https binding and the MexdataExchange http binding?
It seems I can only either select the http base address or the https base address but not both.
Thanks
-
2008年4月17日 0:07
This is a significant issue because in the real world, most websites have multiple host headers (for multiple domain prefixes .com .net .org as well as for www and nonwww domain names).
Anyways, I just came accross the solution for .net 3.5: http://blogs.msdn.com/rampo/archive/2008/02/11/how-can-wcf-support-multiple-iis-binding-specified-per-site.aspx
Shan
- 已建议为答案 alexsilverrose 2009年11月30日 16:39
-
2008年5月27日 3:43
This is an INCREDIBLY important scenario. The inability for WCF to host web services on a website with multiple host headers is a major defect. The bottom line is that as soon as a second host header is added to the website, it breaks all of the services running on the website. Please revisit WCF design.
Sincerely,
Shan McArthur
-
2008年6月9日 19:39this is important for me. Seems like without a host header the WSDL is generated using the local machine name. So I need two host headers one for each of the urls that access our site.
-
2008年7月16日 20:58
Wenlong Dong,
Please revisit this issue again. This is a blocking issue for anyone that has existing applications, and they want to use System.ServiceModel.Activation.WebServiceHostFactory to build REST style web services that can respond over multiple hostnames in IIS.
-
2008年9月9日 11:30Until this weird design decision is changed:
http://www.meineck.net/2008/04/wcf-hosting-multiple-wcf-services-as.html
Dan -
2008年9月23日 20:41This is an extremely important issue for me.
My application switches configurations depending on the hostname it's being accessed on.
So, one domain will use one database, whilst another domain could switch to an entirely different database (purely as an example). I'd like my services to also follow this pattern.
With this model, I only want to install the app once, and simply point multiple host names at it in IIS. I don't want to have to upgrade 20 different webs every time I deploy an update. I don't want to have to maintain 20 different web.configs each with their own baseAddressPrefixFilters, just because each site has both a www.mydomain.com and a mydomain.com. This design decision seems extremely restrictive and causes obvious problems in very common hosting scenarios. In my opinion it would be well worth revisiting!
Pete -
2008年11月13日 16:36Another enthusiastic vote for multiple hostnames per scheme (http) support.
For the use case that the service must listen on multiple host names (a typical scenerio in enterprise deployment.), the workaround that specifies multiple hostnames as absolute URIs in the config file has a serious flaw - httpGet cannot be enabled.
The httpGetEnabled functionality in the serviceMetadata service behavior only supports relative paths that are in the IIS collection. Basically, if this workaround is used, an absolute path must also be specified in the httpGetUrl attribute. This service behavior does not support multiple absolute paths - it is not possible to enable httpGet for the service if the workaround is used. -
2009年1月8日 18:37
This may be a solution for those whose web servers have multiple host headers defined and each web servers may have a different set of host headers.
Since WCF services hosted in IIS can have only one Base Address so we can create a custom service factory to intercept and create a System.ServiceModel.ServiceHost for a specific type of service with a dynamic URI or base address that is from the request URL.
To do this:
1) In your .svc file:
Add the Factory attribute as the following:
<%@ ServiceHost Language="C#" Service="YourNameSpace.RssService" CodeBehind="~/App_Code/Service.cs" Factory="YourNameSpace.DynamicMultipleHostHeadersBinding" %>
2) In your Service.cs file:
Add the following class to your service.cs file:
namespace YourNameSpace
{public class DynamicMultipleHostHeadersBinding : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
Uri[] dynamicAddress = new Uri[1];
dynamicAddress[0] = GetDynamicURI();
return base.CreateServiceHost(serviceType, dynamicAddress);
}
Uri GetDynamicURI()
{
String hostName = String.Format("{0}{1}/YourWebApplication/Service.svc", ((String.Compare(HttpContext.Current.Request.ServerVariables["HTTPS"], "on", true) == 0) ? "https://" : "http://"), HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToString());
return new Uri(hostName);
}
}
....
....
}3) Complile and run.
Hope this helps,
Kevin Duong
-
2009年1月20日 16:30+1 for this being important and needing to be fixed. ASAP. This is a huge barrier for WCF.
-
2009年1月20日 16:42kmd888 said:
This may be a solution for those whose web servers have multiple host headers defined and each web servers may have a different set of host headers.
Since WCF services hosted in IIS can have only one Base Address so we can create a custom service factory to intercept and create a System.ServiceModel.ServiceHost for a specific type of service with a dynamic URI or base address that is from the request URL.
To do this:
1) In your .svc file:
Add the Factory attribute as the following:
<%@ ServiceHost Language="C#" Service="YourNameSpace.RssService" CodeBehind="~/App_Code/Service.cs" Factory="YourNameSpace.DynamicMultipleHostHeadersBinding" %>
2) In your Service.cs file:
Add the following class to your service.cs file:
namespace
YourNameSpace
{public class DynamicMultipleHostHeadersBinding : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
Uri[] dynamicAddress = new Uri[1];
dynamicAddress[0] = GetDynamicURI();
return base.CreateServiceHost(serviceType, dynamicAddress);
}
Uri GetDynamicURI()
{
String hostName = String.Format("{0}{1}/YourWebApplication/Service.svc", ((String.Compare(HttpContext.Current.Request.ServerVariables["HTTPS"], "on", true) == 0) ? "https://" : "http://"), HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToString());
return new Uri(hostName);
}
}
....
....
}3) Complile and run.
Hope this helps,
Kevin Duong
Kevin, I don't believe this solution will work. The problem is that you will get into a first one in wins scenario. So if somebody first hits the service through http then http now becomes your base address so if someone subsequently hits the site through https it won't work. And vice versa. This is the crux of the issue. You can't dynamically build your service endpoint because the first one in wins. This is really a huge issue with WCF and, IMO, should be fixed through a service pack ASAP. -
2009年1月22日 2:17I just want to add one more post about this being a real issue for hosting. One of the bigger reasons for allowing multiple base addresses for multiple host headers is AJAX. Some of us would like to make RESTful services for AJAX calls in our web sites. Notice the term web site and not web application. Sure we could put all of the services on another virtual host called services.foobar.com, but when someone tries to make an XMLHTTPRequest from a page on www.foobar.com, espanol.foobar.com, or pick any other host header that handles that content, they will get an access denied error. So then you will have to mess with setting the domain for the document, which can bring up more issues, specifically, that you might not have full control over all hosts in the foobar.com domain.
So not allowing WCF services to have multiple base addresses for a service means that you cannot actually use WCF to make RESTful services like these. (Which I though was a big reason for the JSON serialization in .Net 3.5) So hopefully someone at MS is reading this and this can be bumped up in priority to maybe make it into a service pack. It is not like MS is worried about adding in large features or changing the behavior of old ones to sell more. (Referring to the action attribute of a form that is runat=server to actually be used... that was a fun issue) -
2009年1月23日 22:45I cant belive microsoft made this by design. I mean every website has two hosts, mywebsite.com and www.mywebsite.com. So obvious.
Mike Flynn -
2009年1月24日 20:19
I agree with all of this - we used WCF as a client server communication mechanism for an off the shelf application (driven by an architect that wants to use the "new hip tech"). In my opinon, WCF is best suited for the quick and dirty internal IT bespoke app. Not for software developers.
I'm seeing more and more of this from Microsoft - things like LINQ and WCF are really "cool" and the Microsoft guys can demo "I put together a whole app framework in 15 min" but jeez - it doesn't scale, it is a b^&U to configure (and keep configured in a user-run-time environment) and we spend more and more time on things breaking due to network configuration, etc. Oversigts such as multiple http headers don't help.
If i'm writing glorified Hello World, WCF is cool - but in the real world, its a bust. Little things like the size limit on Proxy generation using SVCHOST show me that microsoft didn't intend to use it in a scaled enterprise environment.
End rant :)
-
2009年2月20日 10:23I agree too.
Year 2009, developing with the "latest" Microsoft products and.... they do not support the most BASIC things. I mean, virtual hosting has been there years and years.
I'm starting to believe that Microsoft has something against web applications. They plague all their products with small problems/bugs that make development more difficult and problematic.
-
2009年6月11日 2:02hey all, i just had this experience described.
i was getting this error in event viewer:
Exception: System.ServiceModel.ServiceActivationException: The service '/TestService/Service1.svc' cannot be activated due to an exception during compilation. The exception message is: This collection already contains an address with scheme net.tcp. There can be at most one address per scheme in this collection.
Parameter name: item. ---> System.ArgumentException: This collection already contains an address with scheme net.tcp. There can be at most one address per scheme in this collection.
Make sure that you check the C:\windows\system32\inetsrv\config\applicationHost.config file and ensures that there is only one http binding inside the <bindings> element.
I had this problem with net.tcp when i ran appcmd set twice on TCP.
see i had this:
<bindings>
<binding protocol="http" bindingInformation="*:80:" />
<binding protocol="net.tcp" bindingInformation="808:*" />
<binding protocol="net.pipe" bindingInformation="*" />
<binding protocol="net.msmq" bindingInformation="localhost" />
<binding protocol="msmq.formatname" bindingInformation="localhost" />
<binding protocol="net.tcp" bindingInformation="4545:*" />
</bindings>
and i had to manually delete the extra net.tcp to get it to work again.
James Peckham CSM Developer and Agilist http://www.jamespeckham.com -
2009年7月19日 4:18I have the same problem too. I have a web-server with multiple headers + existing webservice. I cannot add my new WCF service to the same website. It has the same error "The exception message is: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection."
This is absolutely a huge problem, for small + middle size businesses.
DQ
David N. -
2009年7月23日 8:39
This is a significant issue because in the real world, most websites have multiple host headers (for multiple domain prefixes .com .net .org as well as for www and nonwww domain names).
Anyways, I just came accross the solution for .net 3.5: http://blogs.msdn.com/rampo/archive/2008/02/11/how-can-wcf-support-multiple-iis-binding-specified-per-site.aspx
Shan
I know it's a year later, but the above solution (on Ram Poornalingam's blog) solved this issue for me, when I had two web-applications hosted on a shared-hosting provider, where the default website had one WCF service defined (using http) and the site in a subdomain (created as a seperate website in IIS, but at wcf.mydomain.com instead of www.mydomain.com) had a separate WCF service (also using http) defined.
So if any other web-developers run into this issue, using the <baseAddressPrefixFilters> element (and simply adding the subdomain, without any port number, as a prefix) worked. Thanks Shan!
Technology Applied -
2009年9月16日 4:09Couldn't agree more. This is really a severe issue!
-
2009年10月8日 13:19
I found a nice alternative here:
http://www.webhost4life.com/HostingKB/KnowledgebaseArticle50088.aspx<servicehostingenvironment>
<baseaddressprefixfilters>
<add prefix="http://www.example.com">
</add>
</baseaddressprefixfilters></servicehostingenvironment></system.servicemodel>
-
2009年11月16日 20:53Thanks for this post, it solved our problem. After reading so many similar solutions and none working this was a great and simple fix. In our case it was the addition of a secure URL that resulted in the second binding entry, the first should have been removed when the default https binding was removed but it was not.
-
2010年7月7日 12:41
I found a nice alternative here:
http://www.webhost4life.com/HostingKB/KnowledgebaseArticle50088.aspx<servicehostingenvironment>
<baseaddressprefixfilters>
<add prefix="http://www.example.com ">
</add>
</baseaddressprefixfilters></servicehostingenvironment></system.servicemodel>
This looked very promising however I am having trouble applying the solution. I have IIS7.5 2008 RC2 .net 3.5 Web application server. Only just found this issue as I am migrating between lab domains however I need both working at the same time. I figured it was no different to a hosted solution with multiple domains but I think I am missing something.
In IIS I have two host headers applied
server.labdomain.com 80 *
server.lab.domain.com 80 *
If I remove one of the headers from IIS all works fine but is undesirable.
If I try the following config as described in the article it just ignores it with the same "This collection already contains an address with scheme http" error message.
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"> <baseAddressPrefixFilters> <add prefix="http://server.labdomain.com"/> </baseAddressPrefixFilters> </serviceHostingEnvironment> <service behaviorConfiguration="MyApplication.WebServices.MyBehavior" name="MyApplication.WebServices.MyService"> <endpoint address="http://server.lab.domain.com/myapplication/webservices/myservice.svc/basic" binding="basicHttpBinding" contract="MyApplication.WebServices.IMyService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="http://server.lab.domain.com/myapplication/webservices/public.svc/mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <endpoint address="http://server.lab.domain.com/myapplication/webservices/public.svc/ws" binding="wsHttpBinding" contract="MyApplication.WebServices.IMyService"> <identity> <dns value="localhost" /> </identity> </endpoint> </service>
Some advice would be appreciated.
-
2011年8月12日 14:44
No kidding. At 1:30 am I couldn't believe my Ajax wasn't working. All sites have a minimum of 2 headers.
The designer must have split coffee on himself when they discussed this.
-
2011年8月17日 22:57
Thank you! This worked for me. All that I had to do was update my web.config file with the <baseAddressPrefixFilters> tags and everything worked great. The rest of this mess was generated by VS2008 when I created this WCF Service. I also added a crossdomain.xml and clientaccesspolicy.xml files to my website and the add service reference silverlight project menu item pulled in the service reference and generated the proxy perfectly. I had three web sites on the same computer. Thanks again.
<
bindings
>
<
customBinding
>
<
binding name="customBinding0"
>
<
binaryMessageEncoding
/>
<
httpTransport
/>
</
binding
>
</
customBinding
>
</
bindings
>
<
serviceHostingEnvironment aspNetCompatibilityEnabled="true"
>
<
baseAddressPrefixFilters
>
<
add prefix="http://www.grovesrobotics.com"
/>
</
baseAddressPrefixFilters
>
</
serviceHostingEnvironment
>
<
services
>
<
service behaviorConfiguration="SA.Web.SAWCFBehavior" name="SA.Web.SAWCF"
>
<
endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
contract="SA.Web.SAWCF"
/>
<
endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
/>
</
service
>
</
services
>