WCF 服务启动错误“此集合已包含一个地址,其方案为 http"; [英] WCF service startup error "This collection already contains an address with scheme http"

查看:35
本文介绍了WCF 服务启动错误“此集合已包含一个地址,其方案为 http";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个 Web 应用程序,其中包含一个 WCF 服务契约和一个调用该 WCF 服务的 Silverlight 控件.在我的开发和测试服务器上,它运行良好.

当我部署到我们的实时服务器并运行应用程序时,我得到一个 System.ServiceModel.ServiceActivationException 类型的异常,它指出由于编译期间出现异常,无法激活该服务.例外是:

<块引用>

这个集合已经包含一个带有 http 方案的地址.此集合中每个方案最多只能有一个地址.

我读到如果网站有多个主机标头,则可能会引发此异常,这在我们的实时服务器上是正确的.显然,IIS 中承载的 WCF 服务只能有一个基地址.我该如何解决这个问题?

解决方案

总结,

代码解决方案:这里

配置解决方案:这里

Mike Chaliy 的帮助下,我找到了一些有关如何通过代码执行此操作的解决方案.因为这个问题几乎会影响我们部署到实时环境的所有项目,所以我坚持纯粹的配置解决方案.我最终找到了一个详细说明如何在 .net 3.0 和 .net 3.5 中执行此操作的文章.

取自该站点,以下是如何更改应用程序 Web 配置的示例:

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

<块引用>

在上面的例子中,net.tcp://payroll.myorg.com:8000 和http://shipping.myorg.com:9000 是只有基地址,对于他们各自的计划,这将是允许通过.这baseAddressPrefixFilter 没有支持任何通配符.

IIS 提供的 baseAddresses 可能有地址绑定到其他方案baseAddressPrefixFilter 中不存在列表.这些地址不会过滤掉了.

Dns 解决方案(未经测试):我认为,如果您创建了一个特定于您的 Web 应用程序的新 dns 条目,添加了一个新网站,并为其提供了一个与 dns 条目匹配的主机标头,您将完全缓解这个问题,并且不必编写自定义代码或为您的 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.

这篇关于WCF 服务启动错误“此集合已包含一个地址,其方案为 http";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆