WCF服务启动错误"此集合已经包含方案的地址http"错误、地址、方案、WCF

2023-09-02 01:37:55 作者:风吹裤裆、屁屁凉

我建立包含一个WCF服务合同和Silverlight控件,这使得调用该WCF服务的Web应用程序。在我开发和测试服务器,它的伟大工程。

当我部署到我们活的服务器并运行我得到一个异常类型的应用程序 System.ServiceModel.ServiceActivati​​onException 其中指出,服务不能因激活在编译过程中的异常。唯一的例外是:

  

此集合已经包含方案http的地址。可以有每个方案中最多只有一个地址,在此集合。

我看了,如果网站有多个主机头,这是我们生活的服务器上真正的这个异常可能被抛出。在IIS中承载显然WCF服务只能有一个基址。我怎样才能解决这个问题得到什么呢?

解决方案

摘要

code解决方案: Here

配置解决方案: Here

随着迈克Chaliy 的帮助下,我发现如何通过code做了一些解决方案。因为这个问题会影响到pretty的很多的所有项目,我们部署到现场的环境我坚持了一个纯粹的配置解决方案。我终于找到了一个详细介绍了如何做,在.NET 3.0和.NET 3.5。

从拍摄现场,下面是如何改变应用程序的Web配置的例子:

 < system.serviceModel>
    < serviceHostingEnvironment>
        < baseAddress prefixFilters>
            <增加preFIX =的net.tcp://payroll.myorg.com:8000/>
            <增加preFIX =htt​​p://shipping.myorg.com:9000/>
        < / baseAddress prefixFilters>
    < / serviceHostingEnvironment>
< /system.serviceModel>
 
WCF的宿主 WCF的配置文件

  

在上面的例子中,   的net.tcp://payroll.myorg.com:8000    http://shipping.myorg.com:9000 是   只有基址,其   各自的方案,这将是   允许经之地。该   baseAddress prefixFilter不   支持任何通配符。

     

由IIS提供的baseAddresses可能   已地址绑定到其他方案   没有present在baseAddress prefixFilter   名单。这些地址将不   过滤掉。

DNS解决方案(未经测试): 我认为,如果你创建了特定于Web应用的新DNS条目,增加了一个新的网站,并赋予它一个主机头相匹配的DNS条目,你会完全缓解这个问题,就不必编写自定义code或加prefixes到你的web.config文件。

I built a web application containing a WCF service contract and a Silverlight control which makes calls to that WCF service. On my development and test servers it works great.

When I deploy to our live server and run the application I get an exception of type System.ServiceModel.ServiceActivationException which states that the service can not be activated due to an exception during compilation. The exception is:

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

I read that this exception may be thrown if the web site has more than one host header, which is true on our live server. Apparently WCF services hosted in IIS can have only one base address. How can I get around this issue?

解决方案

Summary,

Code solution: Here

Configuration solutions: Here

With the help of Mike Chaliy, I found some solutions on how to do this through code. Because this issue is going to affect pretty much all projects we deploy to a live environment I held out for a purely configuration solution. I eventually found one which details how to do it in .net 3.0 and .net 3.5.

Taken from the site, below is an example of how to alter your applications web config:

<system.serviceModel>
    <serviceHostingEnvironment>
        <baseAddressPrefixFilters>
            <add prefix="net.tcp://payroll.myorg.com:8000"/>
            <add prefix="http://shipping.myorg.com:9000"/>
        </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
</system.serviceModel>

In the above example, net.tcp://payroll.myorg.com:8000 and http://shipping.myorg.com:9000 are the only base addresses, for their respective schemes, which will be allowed to be passed through. The baseAddressPrefixFilter does not support any wildcards .

The baseAddresses supplied by IIS may have addresses bound to other schemes not present in baseAddressPrefixFilter list. These addresses will not be filtered out.

Dns solution (untested): I think that if you created a new dns entry specific to your web application, added a new web site, and gave it a single host header matching the dns entry, you would mitigate this issue altogether, and would not have to write custom code or add prefixes to your web.config file.