我已经阅读了很多文章来解决这个问题,但我无法解决它。
方案 我有一个网站,它有一个WCF服务和2个主机头
但是使用相同的端口 44001 我可以访问spin-localhost服务但无法访问spin-localhost.worldwide.co.uk(现在是spin-localhost2)。
编码
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="WindowsAuth" maxReceivedMessageSize="2097152">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior" name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceive">
<endpoint address="http://spin-localhost:44001/Services/CilsDataReceive.svc" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive" />
<endpoint address="http://spin-localhost.worldwide.co.uk:44001/Services/CilsDataReceive.svc" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive" />
</service>
</services>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://spin-localhost:44001" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
上述解决方案失败我尝试了工厂
public class CustomHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
return new ServiceHost(serviceType, baseAddresses[0]);
}
}
编辑:我使用的是/ Net 3.5而不是4。
参考 http://www.sieena.com/blog/archive/2011/02/01/wcf-service-in-iis-with-multiple-host-headers.aspx
http://blogs.msdn.com/b/rampo/archive/2007/06/15/supporting-multiple-iis-bindings-per-site.aspx
http://social.msdn.microsoft.com/forums/en-US/wcf/thread/9e248455-1c4d-4c5c-851c-79d9c1631e21/
还有更多......
更新1:经过进一步测试后,似乎global.bbc.co.uk出现了错误,所以我将名称和绑定更改为spin-localhost2。
<endpoint address="http://spin-localhost2:44001/Services/CilsDataReceive.svc" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive" />
我可以使用spin-localhost访问第一个服务,但spin-localhost2提供401,401然后400(未找到)。用Fiddler检查了它。
解决方案(尚未测试):
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior">
<!-- <serviceMetadata httpGetEnabled="true" />-->
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Windows"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="WindowsAuth" maxReceivedMessageSize="2097152">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior" name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceive">
<endpoint address="" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
答案 0 :(得分:1)
在vesion 4下使用.NET的WCF不支持多个主机头IIS主机,有一些解决方法,根据您的.NET版本或多或少复杂。
.NET 4.0中的WCF支持将此作为在配置中使用<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
启用的选择加入功能。
答案 1 :(得分:0)
带有IIS的WCF将支持多个端点,其中不同的相对地址为shown in this blog post,但我认为IIS不会在同一端口和同一网站上支持不同的主机头/应用。尝试创建单独的IIS网站,每个主机标头一个,并为每个服务使用单独的serviceModel配置。这样,您可以为您创建的服务使用相同的端口。