在 IIS 上托管 WCF Web 服务在导航到 SVC 文件时引发参数异常
Hosting WCF Web Service on IIS Throws Argument Exception When Navigating to SVC File
我试图在 IIS 上托管 WCF Web 服务,但是当我导航到虚拟 svc 文件时,我分别收到以下参数和服务激活异常:
This collection already contains an address with scheme http. There
can be at most one address per scheme in this collection...
The service '/SidService.svc' cannot be activated due to an exception
during compilation. The exception message is: This collection already
contains an address with scheme http.
我可以使用 IIS Express 在本地 运行 它并成功导航到 svc 文件。当项目部署到服务器 运行ning IIS 7.5 时出现问题。
我正在使用声明性语法来配置 Web 服务,因此没有以编程方式配置任何内容。
<system.serviceModel>
<services>
<service name="Services.SidManager"
behaviorConfiguration="SidManagerBehavior">
<endpoint address=""
binding="wsHttpBinding"
contract="Contracts.ISidService"
bindingConfiguration="wsHttpBindingConfig"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBindingConfig" maxReceivedMessageSize="200000">
<reliableSession enabled="true"/>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SidManagerBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentSessions="100"
maxConcurrentCalls="16"
maxConcurrentInstances="116"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment>
<serviceActivations>
<add service="Services.SidManager"
relativeAddress="SidService.svc" />
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
部分错误消息建议将 multipleSiteBindingsEnabled 属性 设置为 true,但启用多个站点绑定并不成功。
此外,我只使用 wsHttpBinding 是否需要启用多个站点绑定或具有多个基址前缀过滤器?
IIS 7.5 是否需要使用不同的配置?
经过进一步研究,我能够确定 IIS 有两个绑定。将 <baseAddressPrefixFilters>
元素添加到 <serviceHostingEnvironment>
,解决了该问题。
我在 MSDN 的论坛上找到了一个 thread,它帮助我解决了问题。
这是我实现的代码:
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://subdomain.domain.name:port/"/>
</baseAddressPrefixFilters>
...
</serviceHostingEnvironment>
我试图在 IIS 上托管 WCF Web 服务,但是当我导航到虚拟 svc 文件时,我分别收到以下参数和服务激活异常:
This collection already contains an address with scheme http. There can be at most one address per scheme in this collection...
The service '/SidService.svc' cannot be activated due to an exception during compilation. The exception message is: This collection already contains an address with scheme http.
我可以使用 IIS Express 在本地 运行 它并成功导航到 svc 文件。当项目部署到服务器 运行ning IIS 7.5 时出现问题。
我正在使用声明性语法来配置 Web 服务,因此没有以编程方式配置任何内容。
<system.serviceModel>
<services>
<service name="Services.SidManager"
behaviorConfiguration="SidManagerBehavior">
<endpoint address=""
binding="wsHttpBinding"
contract="Contracts.ISidService"
bindingConfiguration="wsHttpBindingConfig"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBindingConfig" maxReceivedMessageSize="200000">
<reliableSession enabled="true"/>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SidManagerBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentSessions="100"
maxConcurrentCalls="16"
maxConcurrentInstances="116"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment>
<serviceActivations>
<add service="Services.SidManager"
relativeAddress="SidService.svc" />
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
部分错误消息建议将 multipleSiteBindingsEnabled 属性 设置为 true,但启用多个站点绑定并不成功。
此外,我只使用 wsHttpBinding 是否需要启用多个站点绑定或具有多个基址前缀过滤器?
IIS 7.5 是否需要使用不同的配置?
经过进一步研究,我能够确定 IIS 有两个绑定。将 <baseAddressPrefixFilters>
元素添加到 <serviceHostingEnvironment>
,解决了该问题。
我在 MSDN 的论坛上找到了一个 thread,它帮助我解决了问题。
这是我实现的代码:
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://subdomain.domain.name:port/"/>
</baseAddressPrefixFilters>
...
</serviceHostingEnvironment>